您的位置:首页 > 编程语言 > C#

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

2016-04-05 13:52 351 查看
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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: