ListView Help

Discussion in 'Microsoft VB .NET' started by samoore33, Sep 7, 2006.

  1. samoore33

    samoore33 Guest

    I found this code on MSDN, and it works great. It creates a ListView
    dynamically and add items to it and all. It is great. I have changed a
    few of the column names to suit me.

    Dim listView1 As New ListView

    listView1.Bounds = New Rectangle(New Point(10, 10), New
    Size(300, 200))

    ' Set the view to show details.
    listView1.View = View.Details
    ' Allow the user to edit item text.
    listView1.LabelEdit = True
    ' Allow the user to rearrange columns.
    listView1.AllowColumnReorder = True
    ' Display check boxes.
    listView1.CheckBoxes = True
    ' Select the item and subitems when selection is made.
    listView1.FullRowSelect = True
    ' Display grid lines.
    listView1.GridLines = True
    ' Sort the items in the list in ascending order.
    listView1.Sorting = SortOrder.Ascending

    ' Create columns for the items and subitems.
    listView1.Columns.Add("Item", -2, HorizontalAlignment.Left)
    listView1.Columns.Add("State", -2, HorizontalAlignment.Left)
    listView1.Columns.Add("Flat", -2, HorizontalAlignment.Left)
    listView1.Columns.Add("Minimum", -2,
    HorizontalAlignment.Center)
    listView1.Columns.Add("Maximum", -2,
    HorizontalAlignment.Center)
    listView1.Columns.Add("Value", -2, HorizontalAlignment.Center)

    ' Create three items and three sets of subitems for each item.
    Dim item1 As New ListViewItem("item1", 0)
    ' Place a check mark next to the item.
    'item1.Checked = True
    item1.SubItems.Add("1")
    item1.SubItems.Add("2")
    item1.SubItems.Add("3")
    Dim item2 As New ListViewItem("item2", 1)
    item2.SubItems.Add("4")
    item2.SubItems.Add("5")
    item2.SubItems.Add("6")
    Dim item3 As New ListViewItem("item3", 0)
    ' Place a check mark next to the item.
    'item3.Checked = True
    item3.SubItems.Add("7")
    item3.SubItems.Add("8")
    item3.SubItems.Add("9")

    'Add the items to the ListView.
    listView1.Items.AddRange(New ListViewItem() {item1, item2,
    item3})

    MY ATTEMPT TO ADD THIS INFORMATION INTO A LISTVIEW ALREADY ON THE FORM
    'lsvTest.Items.AddRange(New ListViewItem() {item1, item2,
    item3})

    ' Add the ListView to the control collection.
    Me.Controls.Add(listView1)

    The problem is that I am trying to add information to a ListView that
    is already a control on the form. It seems know matter what I try,
    nothing will add to my listview. My unltimate goal is to add items from
    a dataset to the listview. It does not seem to be an easy task to
    complete, especially since the dataset has more then one table in it.

    Any help would be appreciated.

    Thanks.

    Scott Moore
     
    samoore33, Sep 7, 2006
    #1
    1. Advertisements

  2. samoore33

    samoore33 Guest

    As usual I was forgetting something, that is why I could not get any of
    the information to show up in the ListView that I had added to the
    form.

    Now the fun part of figuring out how to add the information to the
    listview. I think I know how to do that though, I should be able to
    create a class that will help me add items to the listview.

    Maybe I do not need a group, I just need someone to play like they are
    listening to me while I think outloud.

    Scott

    samoore33 wrote:
    > I found this code on MSDN, and it works great. It creates a ListView
    > dynamically and add items to it and all. It is great. I have changed a
    > few of the column names to suit me.
    >
    > Dim listView1 As New ListView
    >
    > listView1.Bounds = New Rectangle(New Point(10, 10), New
    > Size(300, 200))
    >
    > ' Set the view to show details.
    > listView1.View = View.Details
    > ' Allow the user to edit item text.
    > listView1.LabelEdit = True
    > ' Allow the user to rearrange columns.
    > listView1.AllowColumnReorder = True
    > ' Display check boxes.
    > listView1.CheckBoxes = True
    > ' Select the item and subitems when selection is made.
    > listView1.FullRowSelect = True
    > ' Display grid lines.
    > listView1.GridLines = True
    > ' Sort the items in the list in ascending order.
    > listView1.Sorting = SortOrder.Ascending
    >
    > ' Create columns for the items and subitems.
    > listView1.Columns.Add("Item", -2, HorizontalAlignment.Left)
    > listView1.Columns.Add("State", -2, HorizontalAlignment.Left)
    > listView1.Columns.Add("Flat", -2, HorizontalAlignment.Left)
    > listView1.Columns.Add("Minimum", -2,
    > HorizontalAlignment.Center)
    > listView1.Columns.Add("Maximum", -2,
    > HorizontalAlignment.Center)
    > listView1.Columns.Add("Value", -2, HorizontalAlignment.Center)
    >
    > ' Create three items and three sets of subitems for each item.
    > Dim item1 As New ListViewItem("item1", 0)
    > ' Place a check mark next to the item.
    > 'item1.Checked = True
    > item1.SubItems.Add("1")
    > item1.SubItems.Add("2")
    > item1.SubItems.Add("3")
    > Dim item2 As New ListViewItem("item2", 1)
    > item2.SubItems.Add("4")
    > item2.SubItems.Add("5")
    > item2.SubItems.Add("6")
    > Dim item3 As New ListViewItem("item3", 0)
    > ' Place a check mark next to the item.
    > 'item3.Checked = True
    > item3.SubItems.Add("7")
    > item3.SubItems.Add("8")
    > item3.SubItems.Add("9")
    >
    > 'Add the items to the ListView.
    > listView1.Items.AddRange(New ListViewItem() {item1, item2,
    > item3})
    >
    > MY ATTEMPT TO ADD THIS INFORMATION INTO A LISTVIEW ALREADY ON THE FORM
    > 'lsvTest.Items.AddRange(New ListViewItem() {item1, item2,
    > item3})
    >
    > ' Add the ListView to the control collection.
    > Me.Controls.Add(listView1)
    >
    > The problem is that I am trying to add information to a ListView that
    > is already a control on the form. It seems know matter what I try,
    > nothing will add to my listview. My unltimate goal is to add items from
    > a dataset to the listview. It does not seem to be an easy task to
    > complete, especially since the dataset has more then one table in it.
    >
    > Any help would be appreciated.
    >
    > Thanks.
    >
    > Scott Moore
     
    samoore33, Sep 7, 2006
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Norman Fritag

    Newbie asking for help Populating listview Control ??

    Norman Fritag, Dec 31, 2003, in forum: Microsoft VB .NET
    Replies:
    5
    Views:
    169
    Russ Green
    Dec 31, 2003
  2. Andy
    Replies:
    0
    Views:
    174
  3. OpticTygre

    Listview help

    OpticTygre, Jul 23, 2004, in forum: Microsoft VB .NET
    Replies:
    3
    Views:
    145
    OpticTygre
    Jul 23, 2004
  4. Peter
    Replies:
    0
    Views:
    360
    Peter
    Feb 24, 2005
  5. Rita
    Replies:
    0
    Views:
    386
Loading...

Share This Page