zoukankan      html  css  js  c++  java
  • winform编程设定listview选中行

    在做项目中,需要用到listview显示数据。同时,项目要求,通过检索用户输入的数据,程序通过搜索,确定数据所在的行并通过程序设定为选中状态并高亮显示。同时,正常响应鼠标单击响应的效果,单击时,程序设定的选中行清除选中状态。类似的效果如下:

    以选中第4行为例,我的实现代码如下:

               //更改listView属性
                this.listViewUser.GridLines = true;//显示表格线
                this.listViewUser.View = View.Details;//显示表格细节
                this.listViewUser.LabelEdit = true;//是否可编辑,ListView只可编辑第一列
                this.listViewUser.Scrollable = true;//有滚动条
                this.listViewUser.HeaderStyle = ColumnHeaderStyle.Clickable;//对表头进行设置
                this.listViewUser.FullRowSelect = true;//是否可以选择行
                this.listViewUser.HideSelection = false;


                listViewUser.SelectedItems.Clear();
                this.listViewUser.Items[3].Selected = true;//设定选中            
                this.listViewUser.Items[3].EnsureVisible();//保证可见
                this.listViewUser.Items[3].Focused = true;
                this.listViewUser.Select();

    说明:HideSelection属性必须为false

    Select()的作用是激活控件,使用Focus()作用不明显,选中行背景不明显类似为灰色。

  • 相关阅读:
    pt-tcp-model
    (转)从史上八大MySQL宕机事故中学到的经验
    pt-query-digest
    DNS生效时间
    Python之uuid模块
    一个IO的传奇一生
    Python之Queue模块
    利用freemarker 静态化网页
    FreeMarker教程
    模板引擎freemarker的简单使用教程
  • 原文地址:https://www.cnblogs.com/wanghang/p/6299052.html
Copyright © 2011-2022 走看看