Click here to Skip to main content
11,411,840 members (65,753 online)
Click here to Skip to main content

Groupable ListView

, 15 Sep 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
Extended ListView with GUIs for easy grouping.

Sample Image - GroupableListView.png


Some time ago, I thought about writing a small extension to the ListView control. This would dynamically create a graphic user interface to allow the end-user create/modify groups, something like ‘GROUP BY’ in SQL. The control will automatically create a ToolStrip and a ToolStripButton for each column.


To use the control, just add ExListView.cs to your project, and switch the GroupsGUIs property to true, if you want to give the possibility to group items for the users.


  • GroupsGUIs - Show or not the ToolStrip to allow group items.
  • ToolStripImage - The image to show on ToolStripButtons of the groups.
  • ShowGroupLabel - Show or hide the 'ShowGroup' label.
  • ShowGroupLabelText - The 'ShowGroup' label. Default: 'Group by:'.


I prepared a small example project, with a ListView which contains some employees. Each employee has a name, sex, and a job. So, if the user wants to group the employees by sex, he just needs to press one button, and the ListView will analyze each ListViewItem and create groups for the data. It creates one group for each different data in selected colums.

Here you see an example of ListView, grouped by Sex and Job:

Sample Image - GroupableListView.png


To analyze and create the groups, I wrote a GroupBy(ColumnHeader[] Headers) method, it’s a simple thread-safe method with a few loops which add groups for each new different data found.

delegate void dGroupBy(ColumnHeader[] Headers);
public void GroupBy(ColumnHeader[] Headers)
    if (this.InvokeRequired)
        dGroupBy d = new dGroupBy(GroupBy);
        this.Invoke(d, new object[] { Headers });
        foreach (ListViewItem lvi in this.Items)
            string header = "";

            foreach (ColumnHeader ch in Headers)
                header += " " + 
            ListViewGroup group = 
                new ListViewGroup(header);
            ListViewGroup found = null;
            foreach (ListViewGroup g in Groups)
                if (g.Header == group.Header)
                { found = g; break; }
            if (found == null)

Sample Image - GroupableListView.png


  • 06/09/06 – v.1.01: Dock fill bug fixed.
  • 20/08/06 – Initial release.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Chief Technology Officer Misakai Ltd.
Ireland Ireland
Roman Atachiants is the guy behind project, a real-time, client-server networking layer (SOA, RPC) for .NET developers. Also the founder of Misakai Ltd..

He is a software engineer and scientist with extensive experience in different computer science domains, programming languages/principles/patterns & frameworks.

His main expertise consists of C# and .NET platform, game technologies, cloud, human-computer interaction, big data and artificial intelligence. He has an extensive programming knowledge and R&D expertise.

Follow on   Twitter

Comments and Discussions

GeneralVery nice extension! PinmemberSam Jacobs17-Mar-10 13:40 
Generalwrite text in Grouping PinmemberRohit Mahajan21-May-08 22:39 
GeneralVista Style Group/Sort PinmemberAlexandru Stanciu27-Feb-08 18:54 
QuestionNo scroll bar PinmemberBill W15-Nov-07 5:29 
QuestionStrange Issue Pinmember-_-_-_-_-_22-Aug-07 22:10 
AnswerRe: Strange Issue Pinmember-_-_-_-_-_22-Aug-07 22:18 
QuestionWidth-Problem when ListView in LargeIcon-Mode PinmemberStephan Mantel17-Jun-07 4:21 
GeneralGrouping Sorted Pinmemberchancer10116-May-07 5:56 
GeneralSeem a bug PinmemberdvptUml3-Apr-07 17:05 
Generaluse combobox instead of a toolstrip... [modified] PinmemberTheCardinal17-Oct-06 22:04 
QuestionExpand/Collapse Group Pinmemberriz3323-Oct-06 23:06 
AnswerRe: Expand/Collapse Group Pinmembersonofdaedalus24-Jan-07 9:23 
QuestionRe: Expand/Collapse Group PinmemberSoxiz11-Jun-07 12:32 
QuestionA Question Pinmemberphonefans15-Sep-06 8:41 
AnswerRe: A Question PinmemberKel_15-Sep-06 10:47 

Firstly, thank you, you just helped me figure out the logic error in the control. Smile | :)
I haven't changed AutoSize property of ToolStrip to false, so that's why it was shorter. So, SizeChanged event was somehow overriding AutoSize property...

Now, if you change AutoSize property of tsGroups on false, you can edit the constructor like this :

        public ExListView()

and Bind() like that:

        protected virtual void Bind()
            if (m_GroupsGUIs)
                if (this.tsGroups.Visible==false)
                    this.tsGroups.Visible = true;
                this.tsGroups.Parent = this.Parent;
                this.tsGroups.Location = new Point(this.Location.X, this.Location.Y - 25);
                 if(tsGroups.Width != this.Width)
                     this.tsGroups.Width = this.Width;
                if (this.tsGroups.Visible)
                    this.tsGroups.Visible = false;

I'm uploading corrected version, thank you Smile | :)

-- Everything is possible, even the impossible! ^_^

GeneralRe: A Question Pinmemberphonefans15-Sep-06 17:52 
GeneralThanks but there is no group if listview is full dock Pinmemberjvhow5-Sep-06 21:59 
GeneralRe: Thanks but there is no group if listview is full dock PinmemberKel_5-Sep-06 23:00 
GeneralI think its great. Pinmemberilovthecov29-Aug-06 2:16 
GeneralRe: I think its great. PinmemberKel_29-Aug-06 2:24 
Questiontree diagram produced by ? PinmemberBillWoodruff26-Aug-06 2:11 
AnswerRe: tree diagram produced by ? PinmemberKel_26-Aug-06 6:51 
QuestionWhy this code ???? PinmemberDotNET7422-Aug-06 8:04 
AnswerRe: Why this code ???? PinmemberSteven Roebert22-Aug-06 12:07 
QuestionReturn of Groupable ListView ....? PinmemberMahesh Sapre20-Aug-06 21:29 
AnswerRe: Return of Groupable ListView ....? Pinmemberdavepermen20-Aug-06 22:01 
GeneralNice idea! PinmemberMartin Lundberg20-Aug-06 10:10 
GeneralRe: Nice idea! PinmemberKel_20-Aug-06 13:12 
GeneralRe: Nice idea! PinmemberPaulC197222-Aug-06 9:14 
GeneralRe: Nice idea! PinmemberJecc11-Sep-06 22:59 
GeneralAwwww PinmemberEd.Poore20-Aug-06 10:05 
GeneralRe: Awwww PinmemberKel_20-Aug-06 13:14 
GeneralRe: Awwww PinmemberEd.Poore20-Aug-06 14:49 
GeneralRe: Awwww PinmemberJamie Nordmeyer15-Sep-06 12:52 
GeneralRe: Awwww PinmemberEd.Poore17-Sep-06 9:33 
QuestionRe: Awwww Pinmemberpinkjones6-Nov-06 5:08 
AnswerRe: Awwww PinmemberJamie Nordmeyer6-Nov-06 5:19 
GeneralNice! PinmemberdzCepheus20-Aug-06 9:34 
GeneralRe: Nice! PinmemberKel_20-Aug-06 13:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150414.5 | Last Updated 15 Sep 2006
Article Copyright 2006 by Kel_
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid