Results 1 to 7 of 7

Thread: add subitems to listview

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2005
    Posts
    30

    add subitems to listview

    I have a listview with 4 columns.
    i added a value in the 1st column like this:

    listview1.Items.add("somevalue");

    how can i add subitems to this:
    I know it's possible in VB.NET to do this with
    listview1.item(0).subitems(1).add("blabla")

    but this doesn't seem to be possible in C#

    anyone knows about this?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: add subitems to listview

    This should help.

  3. #3
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472

    Re: add subitems to listview

    you can also do in this way:
    VB Code:
    1. ListViewItem li = listView1.Items.Add("item1");
    2.             li.SubItems.Add("sub-item1");
    3.             li.SubItems.Add("sub-item2");

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: add subitems to listview

    The code you have posted is trying to call the Add method of a ListViewSubItem object, which does not exist. That code would not work in VB.NET either. You need to remove the index to the Subitems property:
    Code:
    listview1.item(0).subitems(1).add("blabla")
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: add subitems to listview

    yeah use brackets if you're accessing array elements
    listview1.item[0]....
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Apr 2005
    Posts
    30

    Re: add subitems to listview

    ok thanks , that really helped me out

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: add subitems to listview

    Don't forget to resolve your thread from the Thread Tools menu.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width