要在C#的ListView控件中實(shí)現(xiàn)分組顯示,可以使用ListView控件的Group屬性。以下是實(shí)現(xiàn)分組顯示的步驟:
ListView listView = new ListView();
listView.View = View.Details;
ListViewGroup group1 = new ListViewGroup("Group 1");
ListViewGroup group2 = new ListViewGroup("Group 2");
listView.Groups.Add(group1);
listView.Groups.Add(group2);
ListViewItem item1 = new ListViewItem("Item 1");
item1.Group = group1;
ListViewItem item2 = new ListViewItem("Item 2");
item2.Group = group1;
ListViewItem item3 = new ListViewItem("Item 3");
item3.Group = group2;
listView.Items.Add(item1);
listView.Items.Add(item2);
listView.Items.Add(item3);
form.Controls.Add(listView);
通過以上步驟,ListView控件中的ListViewItem將按照指定的分組進(jìn)行顯示。