C# - adding new groups with items and subitems to a listview

Posted by Nike on Stack Overflow See other posts from Stack Overflow or by Nike
Published on 2010-04-20T15:09:50Z Indexed on 2010/04/20 15:13 UTC
Read the original article Hit count: 426

Filed under:
|
|
|

Hello there.

The following code adds a new item, and a new group with the text "Default". If i keep clicking the button, it will just keep adding new items to that particular group.

ListViewItem item = new ListViewItem("");
item.SubItems.Add("");
csslistview.Items.Add(item);

What i'm trying to do, is to add a new group and fill it with one empty item, aswell as one empty subitem. And when i click the button again, i want it to create a new group, and do the same thing. I have a textbox were the user has to fill in the name of the group, so there wont be any groups with the same name (hopefully).

The following code, i think, creates a new group:

ListViewGroup group = new ListViewGroup(newGroupName);
group.Items.Add(newGroupName);
csslistview.Groups.Add(group);

but as empty groups aren't showed, i can't really verify that it actually creates new groups.

Well, thanks in advance. -Nike

© Stack Overflow or respective owner

Related posts about c#

Related posts about listview