码迷,mamicode.com
首页 > 其他好文 > 详细

Dev GridControl 小结3

时间:2017-03-17 14:09:39      阅读:304      评论:0      收藏:0      [点我收藏+]

标签:new   www   word   focus   validate   lte   view   accept   添加记录   

Dev GridControl 小结

//删除记录
this.gridView1.DeleteSelectedRows();
//添加记录
this.gridView1.AddNewRow();

1、确认当前正在编辑的单元格的输入

this.gridview1.CloseEditor();
2、得到单元格数据(0行0列)
string ss=gridView1.GetRowCellDisplayText(0, gridView1.Columns[0]);
string ss = gridView1.GetRowCellValue(0, gridView1.Columns[0]);
3、设置单元格数据(将0行0列的单元格赋值123) 
gridView1.SetRowCellValue(0, gridView1.Columns[0], "123");

//复制最后一行的数据到新行

View.SetRowCellValue(e.RowHandle, View.Columns[0], gridView1.GetRowCellValue(gridView1.GetRowHandle(gridView1.RowCount - 2), gridView1.Columns[0]));

4、保存当前行的值到数据源

this.gridview1.UpdateCurrentRow();
小注: 

        当你使用gridView1.AddNewRow(); 在gridView1上新增一行,并使用SetRowCellValue()函数对新增行相应的列进行赋值后(此时界面上,新增行上已经有值)。 
        此时使用GetRowCellValue()函数来获取列值,仍然会是null。怎么解决呢? 
        在SetRowCellValue()函数赋值后,使用UpdateCurrentRow()将数据更新到gridview1中,此时使用GetRowCellValue()函数就可以获取到值了。

5、DataRowState 成员名称及说明

        Added 该行已添加到 DataRowCollection 中,AcceptChanges 尚未调用。 

        Deleted 该行已通过 DataRow 的 Delete 方法被删除。  
        Detached 该行已被创建,但不属于任何 DataRowCollection。DataRow 在以下情况下立即处于此状态:创建之后添加到集合中之前;或从集合中移除之后。  
        Modified 该行已被修改,AcceptChanges 尚未调用。  
        Unchanged 该行自上次调用 AcceptChanges 以来尚未更改。 

// 遍历所有修改过的行 
foreach (DataRow row in ds.Tables[0].GetChanges().Rows) 
{
}

6、行版本(DataRowVersion) 
        行(DataRow)对象有四种不同的行版本,分别是Current,Original,proposed和default。下面对这些行版本进行简要的说明。 
        Current:表示行的当前值。处于deleted状态的行不存在该行版本。 
        Original:表示行的原始值。处于Added状态的行不存在该行版本 
        Proposed:表示行的建议值。不属于表的行,即处于Detached状态的行存在该行版本;对于正在进行编辑的行,也存在该行版本。 
        Default:表示行的默认版本。处于Added,Modified或则Unchanged状态的行的默认行版本是current;处于deleted状态的行的默认行版本是original。处于Detached状态的行的默认版本是proposed。

7、修改最上面的GroupPanel内容 

代码设置方式:

gridView1.GroupPanelText="1111111";
界面设置方式:

技术分享

效果如下:

技术分享

8、设某一列文字和标题局中显示  

代码设置方式:

gridView1.Columns[0].AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
界面设置方式:

技术分享

 

 

DevExpress.XtraGrid.v13.2

UpdateCurrentRow
//
// 摘要:
//     Validates the focused row and saves its values to the data source.
//
// 返回结果:
//     true if the row has been successfully updated; otherwise, false.
public override bool UpdateCurrentRow();
校验焦点行并保存值到数据源中.
同时 1,更新 Rowstate = Modified ; 2,关闭编辑器    !!单独使用也没有生效

PostEditor
//
// 摘要:
//     Posts the value being edited to the associated data source without closing
//     the active in-place editor.
//
// 返回结果:
//     true if the value being edited has been successfully saved to the associated
//     data source; otherwise, false.
public bool PostEditor();
提交数据到关联的数据源但是并‘不‘关闭活动编辑器,也不会更新行状态


CloseEditor
//
// 摘要:
//     Hides the active editor saving changes made.
public void CloseEditor();
关闭编辑器并保存更改的数据,但是不会更新行状态

 

//效果 : 在未关闭编辑器的情况下,更新编辑器的值到数据源并改变RowState
this.GridView.PostEditor();
this.GridView.UpdateCurrentRow();

 

Dev GridControl 小结3

标签:new   www   word   focus   validate   lte   view   accept   添加记录   

原文地址:http://www.cnblogs.com/lhyqzx/p/6565566.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!