private void DisplayTableWithListview()
{
listView1.GridLines = true;// Whether the grid lines are displayed
listView1.FullRowSelect = true;// Whether to select the entire line
listView1.View = View.Details;// Set display mode
listView1.Scrollable = true;// Whether to show the scroll bar automatically
listView1.MultiSelect = false;// Is it possible to select multiple lines
// Add header(column)
listView1.Columns.Add("ToString(yyyyMMddHHmm)", 160, HorizontalAlignment.Center);
// Add items into table
for (int i = 0; i < 6; i++)
{
ListViewItem item = new ListViewItem();
item.SubItems.Clear();
item.SubItems[0].Text = "Product" + i.ToString();
item.SubItems.Add(i.ToString());
item.SubItems.Add((i + 7).ToString());
item.SubItems.Add((i * i).ToString());
listView1.Items.Add(item);
}
}
Product 0位于列标题的单元格/位置。我希望从第二个单元格开始添加项目。
1条答案
按热度按时间dhxwm5r41#
您可以使用
listView1.Items.Insert(index , item)
在专业索引中添加项目。listview.listviewitemcollection.insert()如果你想项目从第二个单元格开始添加,试试这个: