Windows Develop Bookmark and Share   
 index > Windows Forms Designer > adding a listviewgroup programmically
 

adding a listviewgroup programmically

I got a problem on how to add a list view group programmically, like when the user wants to add a group to the list at run time, it is better to have a code snippet as a guide, thanks!!!

Mike Ong
MikeOng18Blaber  Tuesday, July 28, 2009 11:15 AM

Hi MikeOng18Blaber,

We can create a new ListViewGroup and add it to the Groups of the ListView. When we need to add a item in this group to the ListView, we ought to add the item to the ListView and set its Group property to the added group. This is a code snippet:
//Add a group.

ListViewGroup group = new ListViewGroup();

group.Name = "NewGroup";

group.Header = "New Group";

group.HeaderAlignment = HorizontalAlignment.Center;

this.listView1.Groups.Add(group);

//Add its items.

this.listView1.Items.Add(new ListViewItem { Text = "TextBox", ImageKey = "TextBox", Group = group });

this.listView1.Items.Add(new ListViewItem { Text = "ListBox", ImageKey = "ListBox", Group = group });

Let me know if this helps.
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Thursday, July 30, 2009 5:42 AM

Hi MikeOng18Blaber,

We can create a new ListViewGroup and add it to the Groups of the ListView. When we need to add a item in this group to the ListView, we ought to add the item to the ListView and set its Group property to the added group. This is a code snippet:
//Add a group.

ListViewGroup group = new ListViewGroup();

group.Name = "NewGroup";

group.Header = "New Group";

group.HeaderAlignment = HorizontalAlignment.Center;

this.listView1.Groups.Add(group);

//Add its items.

this.listView1.Items.Add(new ListViewItem { Text = "TextBox", ImageKey = "TextBox", Group = group });

this.listView1.Items.Add(new ListViewItem { Text = "ListBox", ImageKey = "ListBox", Group = group });

Let me know if this helps.
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Thursday, July 30, 2009 5:42 AM
Thanks for the help!!
MikeOng18Blaber  Thursday, August 06, 2009 6:24 AM

You can use google to search for other answers

Custom Search

More Threads

• how to create and access data from resource files
• Shadows Property Problem
• Couldn't find System.ComponentModel.Design.CollectionEditor
• flicking effect
• winform +fillrectangle transparency +onpaint +invalidate
• Form Designer Blank
• The RootDesigner Can't work with generic
• Hiding Column not working
• Visual inheritence problem
• TabControl grayed out in Toolbox