ListView Control

Help Me!! LOL. I can't figure out this darn control. Item and then SubItems. List View Control. Thanks alot.


Answer this question

ListView Control

  • inthefields

    Andreas Johansson wrote:

    You need to add the subitems to the item object. Here is some code that should work.

    Dim lvi as ListViewItem = ListView1.Items.Add("First item")
    lvi.SubItems.Add("First subitem")
    lvi.SubItems.Add("Second subitem")
    lvi = ListView1.Items.Add("Second item")
    lvi.SubItems.Add("First subitem on second item")
    lvi.SubItems.Add("Second subitem on second item")


    Ok now we are getting somewhere lol. All that shows up are the main items not the subitems. I have the View attribute on List

    ListView1.View = List



  • FatherJack

    Hehe, don't worry.

    You have a Name property where you can associate it with a name. This will work as a key. You can ofcourse use a number but it will be converted to a string.

    lvi = ListView1.Items.Add("item1")
    lvi.Name =
    "I1"

    lvi = ListView1.Items("I1")



  • Mr. Turner

    Try Details view instead.

    ListView1.View = Details



  • wpSlider

    It is not so much to figure out, a ListView has Items, each Item can have SubItems

    SubItems is what you see in windows explorer when you have a detailed view. Everything after the filename are subitems.



  • ebence

    Nothing shows up because Details view needs columns to be defined. I use MSDN as my source for information.

    ListView1.Columns.Add("col1")
    ListView1.Columns.Add("col2")
    ListView1.Columns.Add("col3")



  • TRodS

    The SelectedItems gives an array of selected items. It can contain 0 items when there is no selections so you will have to check for that.

    If ListView1.SelectedItems.Count > 0 Then
    TextBox1.Text = ListView1.SelectedItems(0).Text ' or .Name if that is what you want
    End If



  • nobsay

    Thank You Very Much

    Your gonna hate me lol. Isn't there a way to add a key to that first item I'm use to vb 6. This stuff is so diff than vb 6. Like first item would hold the key value of 1 second item would hold the key value of 2.



  • Ramin

    Now nothing shows up. I can't even find anything on this subject when I search the web.

  • ConfusedJohn

    Ok Mr. Andreas how would I reference that Another words:

    User Clicks on First Item "T1" on my form I also have a text box and "T1" would appear. If User clicks on second Item "T2" then "T2 would appear in the text box.

    Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged

    Me.TextBox1.Text = Me.ListView1."What goes here "

    End Sub

    Thank you so much again. I'll quit bugging you soon.



  • DevLady

    You need to add the subitems to the item object. Here is some code that should work.

    Dim lvi as ListViewItem = ListView1.Items.Add("First item")
    lvi.SubItems.Add("First subitem")
    lvi.SubItems.Add("Second subitem")
    lvi = ListView1.Items.Add("Second item")
    lvi.SubItems.Add("First subitem on second item")
    lvi.SubItems.Add("Second subitem on second item")




  • Digitalboy

    Yeah I know but can't figure out how to get them there.

    ListView1.Items.Add("First Column")

    ListView1.Items.Subitems.Add("Second Column")

    I know this isn't right.



  • ListView Control