C# listView1添加后怎么不显示
的有关信息介绍如下:楼至,记住几个关键的问题
a、记得添加列既是column
b、记得设置view属性为deteils
代码是最好的解释,请看
private void Form1_Load(object sender, EventArgs e)
{
listView1 .View = View .Details ;
ColumnHeader clh;
clh=new ColumnHeader ();
clh .Text ="姓名";
listView1 .Columns .Add (clh );
clh=new ColumnHeader ();
clh .Text ="学号";
listView1 .Columns .Add (clh );
clh = new ColumnHeader();
clh .Text ="性别";
listView1 .Columns .Add (clh );
clh = new ColumnHeader();
clh .Text ="成绩";
listView1 .Columns .Add (clh );
//以上代码为添加列
//下面添加组。用性别分组
ListViewGroup grp;
grp=new ListViewGroup ();
grp.Header = "男";
listView1 .Groups .Add (grp);
grp=new ListViewGroup ();
grp.Header ="女";
listView1 .Groups .Add (grp);
//下面添加信息
ListViewItem lvi;
lvi =new ListViewItem ();
lvi .Text ="张三 ";
lvi.SubItems.Add ("200813340301");
lvi.SubItems.Add("男");
lvi.SubItems.Add ("90");
lvi.Group = listView1.Groups[0];
listView1.Items.Add(lvi);
// listView1.Groups[0].Items.Add(lvi);
lvi =new ListViewItem ();
lvi .Text ="李华 ";
lvi.SubItems.Add ("200813340302");
lvi.SubItems.Add("女");
lvi.SubItems.Add("80");
lvi.Group = listView1.Groups[1];
listView1.Items.Add(lvi);
// listView1.Groups[1].Items.Add(lvi);
}
你多试几次就可以摸索出来道理了,
你看看我给你的效果图吧!