Xtragrid.GridControl

本文详细介绍了GridControl的常用组件及其功能,重点阐述了GridView的使用方法,并提供了获取选中行、删除行、修改数据等操作的示例。此外,还展示了如何清空数据和表格并添加两个列的方法。

下面整理一下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
2
3
int focusedRow= this.gridView1.FocusedRowHandle;
dt.Rows.RemoveAt(focusedRow);
this.gridControl1.DataSource = dt;

4、获取总行数

1
int rownum = this.gridView1.RowCount;

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

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

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

1
2
3
4
5
 //方法一:新建并绑定数据源
 DataTable dt = new DataTable();
 dt.Columns.Add("ID");
 dt.Columns.Add("DATE");
 this.gridControl1.DataSource = dt;
1
2
3
4
5
6
 //方法二:循环删除每条数据
 for (int index = 0; this.gridView1.RowCount-1; index++)
 {
    dt.Rows.RemoveAt(rowindex);
    this.gridControl1.DataSource = dt;
 }
对gridView1中的操作基本都可以通过更改绑定的数据源来实现。增删改是再熟悉不过了,关于gridControl的更多功能,以后会陆续完善。。。

转载于:https://www.cnblogs.com/Jersen/archive/2013/04/27/3046836.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值