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

C# listview如何显示网格线以及如何实现item的选中功能

2014-10-29 10:41 1436 查看
listview控件

1. 常用属性设置

-外观 

FullRowSelect:
True //选中整行

GridLines: True //显示网格线

View: Details

2. 选中整行触发的事件

ItemSelectionChanged

在该事件函数中可以使用 mylistView.FocusedItem来引用你所选中的item。

值得注意的是该时间函数当item由选中变成未选中,会被调用一次;在item由未选中变为选中时又会被调用一次。

故,当你在你的listview里有item 1切换到item 2时,该时间函数会被调用2次。此时,你可以用listView手控.FocusedItem.Selected == true来过滤其中一次调用。

例码如下:

private void listView手控_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
{
if (listView手控.FocusedItem.Selected)
{
button_手控修改.Enabled = true;
button__手控删除.Enabled = true;
}
else
{
button_手控修改.Enabled = false;
button__手控删除.Enabled = false;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c# listview
相关文章推荐