C # ListView showing blank with groups

In VS2005, using C #, I have a Forms application with ListView. I can add items to the list just fine. However, as soon as I try to sort these elements into groups, they are not displayed. I know that groups do not appear when they are empty, but I have confirmed that these groups are not empty. In addition, I set listView.ShowGroups = true. If I add elements to one of the groups, but not the second, the "Default" group appears ... these are just the groups I added that are not displayed!

Here is 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 bands don't appear? Here is a screenshot of what I see:

alt text

+8
c # listview winforms
source share
2 answers

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

You can see an example in the MSDN link

+11
source share

If items are added to the list and ShowGroups set to false and then the ShowGroups property ShowGroups set to true, the list will be displayed empty when showing groups (but with content when ShowGroups false).

ShowGroups must be true when creating the list.

Time is also important. The list must be displayed before the ShowGroups property is set to false. I installed it in my displayed dialog.

I discovered this while working in .Net 4.0.

+5
source share

Source: https://habr.com/ru/post/650023/


All Articles