Windows Develop Bookmark and Share   
 index > Windows Forms General > ListViewGroup ignoring me!
 

ListViewGroup ignoring me!

Hi,

I'm having problems with the ListViewGroup class in the ListView control. There seems to be 10 different ways to achieve the same purpose, that of grouping ListViewItems, but none of them seem to work.

Here is what I have at the moment:

Some background:

I have a simple enough dictionary, whereby the key is a client, which has many contacts.

Code Snippet

Dictionary<IClient, List<IContact>> clientContactDictionary = new Dictionary<IClient, List<IContact>>();

This is populated all fine. eg. I have 17 clients, each with one or more contacts. I want the grouping to be by Client, with ListViewItems representing Contacts.

This is how I am building my listview, known as resultsListView:

Code Snippet

foreach (IClient client in clientContactDictionary.Keys)

{

ListViewGroup lvg=new ListViewGroup(client.ID.ToString(),client.BusinessName);

resultsListView.Groups.Add(lvg);

foreach (IContact contact in clientContactDictionary[client])

{

ListViewItem lvi=new ListViewItem(new string[] { contact.ContactName,contact.EmailAddress },lvg);

lvi.Text = contact.ContactName;

lvi.Tag = contact;

resultsListView.Items.Add(lvi);

resultsListView.Items[resultsListView.Items.Count - 1].Group = lvg;

//Application.DoEvents();

}

}

But is a URL to all I get is the standard listview output:

http://www.programx.me.uk/for_external/03122008/msdn1.jpg

(Forgive gratuitious anonymisation)

Program.X  Wednesday, December 03, 2008 10:52 AM
You'll need to enable Visual Styles so you'll get version 6 of comctl32.dll, the one that supports groups.
nobugz  Wednesday, December 03, 2008 1:53 PM
You'll need to enable Visual Styles so you'll get version 6 of comctl32.dll, the one that supports groups.
nobugz  Wednesday, December 03, 2008 1:53 PM

Thank you very much, I thought it was going to be something daft like that.

Sorted!

Program.X  Wednesday, December 03, 2008 2:00 PM
Unguessable without that screen-shot btw, good move.
nobugz  Wednesday, December 03, 2008 2:07 PM

You can use google to search for other answers

Custom Search

More Threads

• Front/Back Forms in a Multiform, non-MDI App
• MMC 3.0 Snapin
• "A.txt" file is processed by the other application. However, there is no application processing it all all...
• How to load more than 1 million items in ListView without killing the memory?
• Winforms Webbrowser control CAC authentication
• Drawing Complete Controls to Bitmap
• Advanced UI: Use GDI+ or Windows Custom Controls?
• Treeview nodes Compare
• Form designer
• How to change the text colour of the textbox when readonly property is true???