1.为ListView直接添加整行:
myListView.Columns.Add("", 50, HorizontalAlignment.Left);
myListView.Columns.Add("", 50, HorizontalAlignment.Left);
myListView.Columns.Add("", 50, HorizontalAlignment.Left);
myListView.Items.Add(new ListViewItem(new string[] { "张三", "13岁" , "五班"}));
myListView.Items.Add(new ListViewItem(new string[] { "李四", "14岁" , "六班"}));
myListView.Items.Add(new ListViewItem(new string[] { "王五", "15岁" , "七班"}));
2.动态或批量添加行
ListViewItem it;
foreach (MyClass myInfo in MyClassList)
{
it = new ListViewItem();
it.Text = myInfo.Id;
it.SubItems.Add(myInfo.Name);
it.SubItems.Add(myInfo.Age);
it.BackColor = Color.FromArgb(2, 2, 2); //可加判定条件设置行背景颜色
myListView.Items.Add(it);
}
新人整理个人经验,如有错误欢迎指正!