【转】DevExpress.XtraGrid.GridControl 常用功能

mac2022-06-30  82

下面整理一下GridControl 常用的功能, GridControl 包含CardView、GridView、BandedGridView、AdBandedGridView、LayoutView 五个组件,最常用的非GridView莫属。DevExpress.XtraGrid.GridControl 和VS自带的DataGridView非常类似,但使用上有很多的差异。

1、获取选中行的行号

1 int rowIndex = this.gridView1.FocusedRowHandle;

2、获取选中行 的数据

1 string colValue= this.gridView1.GetRowCellValue(this.gridView1.FocusedRowHandle, this.gridView1.Columns[1]).ToString() ;

3、删除选中行数据

1 int focusedRow= this.gridView1.FocusedRowHandle; 2 dt.Rows.RemoveAt(focusedRow); 3 this.gridControl1.DataSource = dt;

4、获取总行数

1 int rownum = this.gridView1.RowCount;

5、插入、删除、修改 数据(增删改)

1 //增加行 2 private void AddRows(string row_num) 3 { 4 dt.Rows.Add(new object[] { row_num, "" }); 5 this.gridControl1.DataSource = dt; 6 } 7 //删除行 8 private void SubRows(int rowindex) 9 { 10 dt.Rows.RemoveAt(rowindex); 11 this.gridControl1.DataSource = dt; 12 } 13 //修改行 14 private void ModifyRows(int rowindex,int colindex,string value) 15 { 16 dt.Rows[rowindex][colindex] = value; 17 this.gridControl1.DataSource = dt; 18 }

6、清空数据和表格 并添加两个列

1 //方法一:新建并绑定数据源 2 DataTable dt = new DataTable(); 3 dt.Columns.Add("ID"); 4 dt.Columns.Add("DATE"); 5 this.gridControl1.DataSource = dt; 1 //方法二:循环删除每条数据 2 for (int index = 0; this.gridView1.RowCount-1; index++) 3 { 4 dt.Rows.RemoveAt(rowindex); 5 this.gridControl1.DataSource = dt; 6 }

对gridView1中的操作基本都可以通过更改绑定的数据源来实现。增删改是再熟悉不过了,关于gridControl的更多功能,以后会陆续完善。。。

转载于:http://www.lockc.com/gridcontrol_usered_functions.html

转载于:https://www.cnblogs.com/Snail-Blog/archive/2013/05/02/3054875.html

相关资源:DevExpress.XtraGrid.GridControl绑定List笔记
最新回复(0)