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

C# ListView 选中状态的判断方法

2007-09-14 12:22 381 查看
 C# ListView 选中状态的判断方法  

问题:

在ListView中先选中一个Item,然后在点Button时能够获得选中的Item的Text,Button中要能够判断Item是否被选中,否则SelectedItems会报错。



实现代码:


        private void button2_Click(object sender, EventArgs e)




        ...{


            if (listView1.FocusedItem != null)




            ...{


                if (listView1.SelectedItems != null)




                ...{


                    MessageBox.Show(listView1.SelectedItems[0].SubItems[1].Text);


                }


            }


        }

默认情况下,上述代码还会有问题,解决方法是将ListView设置成正行选中:

listView1.FullRowSelect = true;

OK!

 

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1747641
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  listview c# button null object
相关文章推荐