现在的位置: 首页 > 综合 > 正文

DeveExpress的将GridView跳转到新添行

2013年12月09日 ⁄ 综合 ⁄ 共 918字 ⁄ 字号 评论关闭

我们在想数据库中添加记录后往往会希望将GridView跳转到新添行,

在DeveExpress中可以这样实现

//根据单位名称定位当前行
string searchtxt = "字符串";
GridColumn column = dataGridView1.Columns["订货单位名称"];
int rhFound = dataGridView1.LocateByDisplayText(dataGridView1.FocusedRowHandle + 1, column, searchtxt);
dataGridView1.FocusedRowHandle = rhFound;

在dataGridView中可以这样实现

//获取行值
dataGridView1.CurrentCell = dataGridView1.Rows[ID].Cells["列名"];

如何定位和查找指定列显示值的行(注意是列的实显示值,而不是关联数据源列值)

using DevExpress.XtraGrid.Views.base;

using DevExpress.XtraGrid.Columns;

string searchText = "Japan";
// obtaining the focused view
ColumnView view = (ColumnView)gridControl1.FocusedView;
// obtaining the column bound to the Country field
GridColumn column = view.Columns["Country"];
if(column != null) {
// locating the row
//如果用数据源中的列值,请用ColumnView.LocateByValue
int rhFound = view.LocateByDisplayText(view.FocusedRowHandle + 1, column, searchText);
// focusing the cell
if(rhFound != GridControl.InvalidRowHandle) {
view.FocusedRowHandle = rhFound;
view.FocusedColumn = column;
}
}


【上篇】
【下篇】

抱歉!评论已关闭.