C#如何将数组信息绑定到ListView
我的ListView是以Details视图显示的,为何不显示啊?求大神修正和指教代码如下:publicEM[]ac=newEM[3];//员工数组publicvoidch...
我的ListView是以Details 视图显示的,为何不显示啊 ?求大神
修正和指教
代码如下:
public EM[] ac = new EM[3];//员工数组
public void chushihua()//员工信息初始化 {
第一个 EM ac1 = new EM(); ac1.gonghao = "001"; ac1.name = "王小毛"; ac1.Sex = "男"; ac1.age = "20"; ac1.pingjia = ""; ac1.defen = "0"; ac[0] = ac1;
第二个 EM ac2 = new EM(); ac2.gonghao = "002"; ac2.name = "张虎业"; ac2.Sex = "男"; ac2.age = "28"; ac2.pingjia = ""; ac2.defen = "0"; ac[1] = ac2;
第三个 EM ac3 = new EM(); ac3.gonghao = "003"; ac3.name = "王美丽"; ac3.Sex = "女"; ac3.age = "25"; ac3.pingjia = ""; ac3.defen = "0"; ac[2] = ac3; }
员工数据绑定到ListView 展开
修正和指教
代码如下:
public EM[] ac = new EM[3];//员工数组
public void chushihua()//员工信息初始化 {
第一个 EM ac1 = new EM(); ac1.gonghao = "001"; ac1.name = "王小毛"; ac1.Sex = "男"; ac1.age = "20"; ac1.pingjia = ""; ac1.defen = "0"; ac[0] = ac1;
第二个 EM ac2 = new EM(); ac2.gonghao = "002"; ac2.name = "张虎业"; ac2.Sex = "男"; ac2.age = "28"; ac2.pingjia = ""; ac2.defen = "0"; ac[1] = ac2;
第三个 EM ac3 = new EM(); ac3.gonghao = "003"; ac3.name = "王美丽"; ac3.Sex = "女"; ac3.age = "25"; ac3.pingjia = ""; ac3.defen = "0"; ac[2] = ac3; }
员工数据绑定到ListView 展开
3个回答
展开全部
(一)我们先建立一个如圆绝二维数组
listView1.View = View.Details;
listView1.Columns.Add("姓名");
listView1.Columns.Add("语文");
listView1.Columns.Add("数学");
listView1.Columns.Add("科学");
listView1.Columns.Add("英语");
string[,] chengji = new string[4, 5];
chengji[0, 0] = "小王"渣姿;
chengji[0, 1] = "90";
chengji[0, 2] = "98";
chengji[0, 3] = "88";
chengji[0, 4] = "92";
chengji[1, 0] = "小李";
chengji[1, 1] = "92";
chengji[1, 2] = "94";
chengji[1, 3] = "98";
chengji[1, 4] = "93";
chengji[2, 0] = "小黄";
chengji[2, 1] = "91";
chengji[2, 2] = "92";
chengji[2, 3] = "93";
chengji[2, 4] = "94";
chengji[3, 0] = "小张";
chengji[3, 1] = "95";
chengji[3, 2] = "94";
chengji[3, 3] = "93";
chengji[3, 4] = "92";
(二)下面是几种分列显示二维数组的几种方法。
1、第一种分列显示方腔让法:
listView1.Clear();
for (int i = 0; i < chengji.GetLength(0); i++)
{
ListViewItem bb = new ListViewItem(new string[] { chengji[i, 0], chengji[i, 1], chengji[i, 2], chengji[i, 3], chengji[i, 4] });
listView1.Items.Add(bb);
}
2、第二种分列显示方法:
上面的listview分列显示还可以用下面的方法。
listView1.Clear();
ListViewItem cj;
for (int i = 0; i < chengji.GetLength(0); i++)
{
cj = new ListViewItem(chengji[i,0]);
cj.SubItems.Add(chengji[i, 1]);
cj.SubItems.Add(chengji[i,2]);
cj.SubItems.Add(chengji[i, 3]);
cj.SubItems.Add(chengji[i, 4]);
listView1.Items.Add(cj);
3、第三种分列显示方法:
如果我们把二维数组转化为一维数组(即结合上面两种方法)还可以用下面的方法分列显示。
listView1.Clear();
ListViewItem cjj;
string[] sstr = new string[chengji.GetLength(1)];
for (int i = 0; i < chengji.GetLength(0); i++)
{
for (int j = 0; j < chengji.GetLength(1); j++)
{
sstr[j] = chengji[i, j];
}
cjj = new ListViewItem(sstr);
listView1.Items.Add(cjj);
}
listView1.View = View.Details;
listView1.Columns.Add("姓名");
listView1.Columns.Add("语文");
listView1.Columns.Add("数学");
listView1.Columns.Add("科学");
listView1.Columns.Add("英语");
string[,] chengji = new string[4, 5];
chengji[0, 0] = "小王"渣姿;
chengji[0, 1] = "90";
chengji[0, 2] = "98";
chengji[0, 3] = "88";
chengji[0, 4] = "92";
chengji[1, 0] = "小李";
chengji[1, 1] = "92";
chengji[1, 2] = "94";
chengji[1, 3] = "98";
chengji[1, 4] = "93";
chengji[2, 0] = "小黄";
chengji[2, 1] = "91";
chengji[2, 2] = "92";
chengji[2, 3] = "93";
chengji[2, 4] = "94";
chengji[3, 0] = "小张";
chengji[3, 1] = "95";
chengji[3, 2] = "94";
chengji[3, 3] = "93";
chengji[3, 4] = "92";
(二)下面是几种分列显示二维数组的几种方法。
1、第一种分列显示方腔让法:
listView1.Clear();
for (int i = 0; i < chengji.GetLength(0); i++)
{
ListViewItem bb = new ListViewItem(new string[] { chengji[i, 0], chengji[i, 1], chengji[i, 2], chengji[i, 3], chengji[i, 4] });
listView1.Items.Add(bb);
}
2、第二种分列显示方法:
上面的listview分列显示还可以用下面的方法。
listView1.Clear();
ListViewItem cj;
for (int i = 0; i < chengji.GetLength(0); i++)
{
cj = new ListViewItem(chengji[i,0]);
cj.SubItems.Add(chengji[i, 1]);
cj.SubItems.Add(chengji[i,2]);
cj.SubItems.Add(chengji[i, 3]);
cj.SubItems.Add(chengji[i, 4]);
listView1.Items.Add(cj);
3、第三种分列显示方法:
如果我们把二维数组转化为一维数组(即结合上面两种方法)还可以用下面的方法分列显示。
listView1.Clear();
ListViewItem cjj;
string[] sstr = new string[chengji.GetLength(1)];
for (int i = 0; i < chengji.GetLength(0); i++)
{
for (int j = 0; j < chengji.GetLength(1); j++)
{
sstr[j] = chengji[i, j];
}
cjj = new ListViewItem(sstr);
listView1.Items.Add(cjj);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
for循环改成类似如下(手写,你自己衫昌仿照陪塌桥芦猛改)
for(...)
{
EM aci = ac[i];
//下面添加的元素是aci相关字段
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询