• Devexpress GridView部分常用操作总结


     一:Clone返回新的 DataTable

    Clone返回新的 DataTable,与当前的 DataTable 具有相同的架构;Copy:返回新的 DataTable,它具有与该 DataTable 相同的结构(表架构和约束)和数据 

    DataRow[] _dr = DT.Select("CLSSBH='"+ Filter_Str +"'"); 
    DataTable dt = DT.Clone() ; 
    DataRow dr ; 
    for( int j = 0 ;j < _dr.Length ;j ++ ) 

    dr = dt.NewRow() ; 
    dr = _dr[j] ; 
    dt.ImportRow( dr ) ; 

      
    我一般使用DataTable.Rows.Add(row.ItemArray); 

     二:选中某一行

    GridView.FocusedRowHandle =i;
    GridView.SelectRow(i);

    三:遍历GridView

    for (int i = 0; i < gridView1.RowCount; i++)
    {
           for (int j = 0; j < gridView1.Columns.Count; j++)
           {
                 object val = gridView1.GetRowCellValue(i, gridView1.Columns[j]);
           }
    }

    四:单元格双击响应

    需要先将gridview1.OptionsBehavior.Editable设为false,然后响应gridControl1_DoubleClick事件。

            private void gridControl1_DoubleClick(object sender, EventArgs e)
            {
                MouseEventArgs arg = e as MouseEventArgs;
                if (arg == null)
                    return;

                GridHitInfo hitInfo = gridView1.CalcHitInfo(new Point(arg.X, arg.Y));//获取坐标点
                if (hitInfo.RowHandle >= 0)
                {
                    DataRow row = gridView1.GetDataRow(hitInfo.RowHandle);
                    _list.Clear();
                    _list.Add(row[0].ToString());
                    gisResoureMonControl1.SetSelectResource(_list);
                }           
            }

    五:GridView隐藏行

    需要响应CustomRowFilter事件,用来设置过滤条件;

    需要根据原始数据源结合起来,才能方便地隐藏或者显示行;

            /// <summary>
            /// 根据条件查询并在表格中显示结果
            /// </summary>
            /// <param name="strCondition"></param>
            private void QueryTable(string strCondition)
            {
                DataTable table = gridControl1.DataSource as DataTable;
                if (table == null)
                    return;

                _indexlist.Clear();

                for (int i = 0; i < table.Rows.Count; i++)
                {
                    for (int j = 0; j < table.Columns.Count; j++)
                    {
                        if(table.Rows[i][j].ToString().Contains(strCondition))
                        {
                            _indexlist.Add(i);
                            gridView1.RefreshData();
                            break;
                        }
                    }
                }

                if (_indexlist.Count==0)
                    HideGridView();                      
            }

            /// <summary>
            /// gridView的行隐藏或显示的过滤条件
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void gridView1_CustomRowFilter(object sender, RowFilterEventArgs e)
            {
                if (_indexlist.Count == 0)
                    return;

                if(_indexlist.Contains(-2))
                    e.Visible = true;   //全显示
                else if (_indexlist.Contains(-3))
                    e.Visible = false;   //全隐藏
                else if(_indexlist.Contains(e.ListSourceRow))
                    e.Visible = true;
                else
                    e.Visible = false;

                e.Handled = true;
            }

    怀仁怀朴,唯真唯实。
  • 相关阅读:
    序列化和反序列化&持久化
    基于qiankun微前端的部署方案
    【MySQL】Explain执行计划 type类型说明
    【ElasticSearch】index read-only
    【MybatisPlus】Wrappers条件构造器构造or条件查询
    【布隆过滤器】基于Resisson的实现的布隆过滤器
    Nacos源码分析(三): 心跳设计
    Nacos源码分析(二):服务端和客户端实例注册
    Nacos源码分析(一): Nacos源码环境搭建
    【linux】如何在linux中查找文件、进程
  • 原文地址:https://www.cnblogs.com/hushzhang/p/14974144.html
Copyright © 2020-2023  润新知