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;
        }

 

转载于:https://www.cnblogs.com/flyhigh1860/archive/2012/06/14/2549856.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值