Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# ListView Appears Blank with Groups

In VS2005, using C#, I have a Forms application with a ListView. I can added items to the listview just fine. However, as soon as I try to sort those items into groups, they don't appear. I know that groups don't appear when they're empty, but I've confirmed these groups are not empty. Also, I am setting listView.ShowGroups = true. If I add items to one of the groups, but not the second, the "Default" group does show up...it's just the groups I've added that don't appear!

Here's the code I'm using:

this.listView.View = View.Details;
this.listView.Columns.Add("Column1");
this.listView.Columns[0].Width = this.listView.Width - 20;
this.listView.HeaderStyle = ColumnHeaderStyle.None;
this.listView.Groups.Add(new ListViewGroup("A"));
this.listView.Groups.Add(new ListViewGroup("D"));


foreach(item i in Class.Items)
{
    if (i.Type == Type.A)
        this.listView.Groups[0].Items.Add(i.Name);
    else
        this.listView.Groups[1].Items.Add(i.Name);
}
this.listView.ShowGroups = true;

Does anyone have any ideas as to why my groups don't show up? Here's a screen shot of what I'm seeing:

alt text

like image 361
JToland Avatar asked Dec 10 '10 15:12

JToland


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.


1 Answers

You should not add items to the group, but rather adding items to the list view, and for each item set its Group property to the desired group.

You can see an example in this MSDN link

like image 61
digEmAll Avatar answered Oct 19 '22 08:10

digEmAll