zoukankan      html  css  js  c++  java
  • WinForm中DataGridView的快速查找及将指定行显示到第一行

            /// <summary>
            /// 快速在已绑定的列表查询车辆
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void btnFind_Click(object sender, EventArgs e)
            {
                // Linq模糊查询  
                IEnumerable<DataGridViewRow> enumerableList = this.dgvCarList.Rows.Cast<DataGridViewRow>();
                List<DataGridViewRow> list = (from item in enumerableList
                                              where item.Cells[2].Value.ToString().IndexOf(this.txtCarCode.Text) >= 0
                                              select item).ToList();
    
                // 恢复之前行的背景颜色为默认的白色背景  
                this.dgvCarList.Rows[beforeMatchedRowIndex].DefaultCellStyle.BackColor = System.Drawing.Color.White;
    
                if (list.Count > 0)
                {
                    // 查找匹配行高亮显示  
                    int matchedRowIndex = list[0].Index;
                    this.dgvCarList.Rows[matchedRowIndex].DefaultCellStyle.BackColor = System.Drawing.Color.Yellow;
                    this.beforeMatchedRowIndex = matchedRowIndex;
                    //dgvCarList.CurrentCell = dgvCarList.Rows[matchedRowIndex].Cells[2];
                    dgvCarList.FirstDisplayedScrollingRowIndex = matchedRowIndex;
                }
            }
    

      

  • 相关阅读:
    编译安装mysql-5.6.36
    MYSQL数据库基础篇
    MYSQL数据库初学者必看
    Centos7下安装与卸载Jdk1.8
    Linux与Window之间的上传与下载
    MySQL主从搭建
    zabbix通过插件percona进行监控MySQL
    suse系统关闭防火墙
    编译安装zabbix3.0
    centos7安装tomcat
  • 原文地址:https://www.cnblogs.com/fjzhang/p/7059635.html
Copyright © 2011-2022 走看看