如何添加子项 [英] how to add subitems
本文介绍了如何添加子项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
先生,如何在 combobox ListView
中的每个Item
中添加SubItems
?
item1 subitem1
item2 subitem2
item3 subitem3
Sir, how to add SubItems
to each Item
in combobox ListView
?
item1 subitem1
item2 subitem2
item3 subitem3
推荐答案
//Set the listview mode
listView1.View = View.Details;
//Add 6 columns to the listview (main item + 5 subitems)
for (int col = 0; col < 6; col++)
{
listView1.Columns.Add("Col " + col.ToString());
}
// Add 10 items to the listview
for (int x = 0; x < 10; x++)
{
ListViewItem newItem = new ListViewItem("Item " + x.ToString());
//Add 5 subitems to listview item
for (int y = 0 ; y < 5; y++)
{
newItem.SubItems.Add(new ListViewItem.ListViewSubItem(newItem,"Subitem " + y.ToString()));
}
//Add the new item to the listview
listView1.Items.Add (newItem);
}
这篇关于如何添加子项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文