c# winform 获取listview 选中行某列的值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
给listview填充数据:          
for (int i = 0; i < 5; i++)
            {
                ListViewItem lvitem = new ListViewItem();
                lvitem.SubItems[0].Text = i.ToString();
                lvitem.SubItems.Add("项目编号"+i.ToString());
                lvitem.SubItems.Add("项目名称" + i.ToString());
                lvitem.SubItems.Add("项目负责人" + i.ToString());
                lvitem.SubItems.Add("项目年度-" + i.ToString());
                listView1.Items.Add(lvitem);
            }
  
将listview选中行的第一列的值输出
private void lvAccountList_SelectedIndexChanged(object sender, EventArgs e)
{
//在此处设断点,发现点击不同的Item后,此事件居然执行了2次 //第一次是取消当前Item选中状态,导致整个ListView的SelectedIndices变为0
//第二次才将新选中的Item设置为选中状态,SelectedIndices变为1
//如果不加listview.SelectedIndices.Count>0判断,将导致获取listview.Items[]索引超界的异常
 
if (listview.SelectedIndices != null && listview.SelectedIndices.Count>0)
{
ListView.SelectedIndexCollection c = listview.SelectedIndices;
lblTitle.Text = listview.Items[c[0]].Text;
}
}

  

c# winform 获取listview 选中行某列的值,布布扣,bubuko.com

c# winform 获取listview 选中行某列的值

上一篇:VS2008上借助VA来提示QT API


下一篇:win7 一些快捷系统工具命令