DevExpress 获取选中单元格DataGridView
DevExpress Get Selected Cell DataGridView
我在获取 datagridview 上选定单元格的 ItemId 时遇到一些问题。列 ItemId 对用户隐藏。
任何帮助将不胜感激。谢谢。
private void btnReturn_Click_1(object sender, EventArgs e)
{
Id = gridView1.GetFocusedDataRow()["ItemId"].ToString();
MessageBox.Show(Id);
}
参考这个 - Obtaining and Setting Cell Values
It is possible to get the values of cells using the methods provided
by the grid's data source. For instance, the ColumnView.GetRow,
ColumnView.GetDataRow, ColumnView.GetFocusedRow and
ColumnView.GetFocusedDataRow methods return objects that
represent rows in a data source. After rows are obtained, use their
methods to retrieve field values.
例如,如果您的网格绑定到 DataTable,那么您可以获取网格中所选行的基础数据行,如下所示:
System.Data.DataRow row = gridView1.GetDataRow(gridView1.FocusedRowHandle);
string cellValue = row[0].ToString();
如果它绑定到某个对象数据源,则使用 GetRow 方法并将其转换为您的 class 对象。然后您可以访问该对象的 .ItemID 属性。
MyClass row = gridView1.GetRow(gridView1.FocusedRowHandle) as MyClass;
if(row != null)
string id= row.ItemID;
希望本文对您有所帮助..
我在获取 datagridview 上选定单元格的 ItemId 时遇到一些问题。列 ItemId 对用户隐藏。
任何帮助将不胜感激。谢谢。
private void btnReturn_Click_1(object sender, EventArgs e)
{
Id = gridView1.GetFocusedDataRow()["ItemId"].ToString();
MessageBox.Show(Id);
}
参考这个 - Obtaining and Setting Cell Values
It is possible to get the values of cells using the methods provided by the grid's data source. For instance, the ColumnView.GetRow, ColumnView.GetDataRow, ColumnView.GetFocusedRow and ColumnView.GetFocusedDataRow methods return objects that represent rows in a data source. After rows are obtained, use their methods to retrieve field values.
例如,如果您的网格绑定到 DataTable,那么您可以获取网格中所选行的基础数据行,如下所示:
System.Data.DataRow row = gridView1.GetDataRow(gridView1.FocusedRowHandle);
string cellValue = row[0].ToString();
如果它绑定到某个对象数据源,则使用 GetRow 方法并将其转换为您的 class 对象。然后您可以访问该对象的 .ItemID 属性。
MyClass row = gridView1.GetRow(gridView1.FocusedRowHandle) as MyClass;
if(row != null)
string id= row.ItemID;
希望本文对您有所帮助..