zoukankan      html  css  js  c++  java
  • Xtragrid.GridControl

    下面整理一下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的更多功能,以后会陆续完善。。。
  • 相关阅读:
    Fragment学习简介与生命周期研究
    POJ 2513 Colored Sticks 【Trie树】
    listView实时更新
    苹果技术支持联系方式
    文件中随机读取行问题
    hdu 4554
    hdu 4556
    离开通讯后就职互联网行业的一些感悟
    HDU1016:Prime Ring Problem
    dbgrideh通用打印
  • 原文地址:https://www.cnblogs.com/Jersen/p/3046836.html
Copyright © 2011-2022 走看看