如何通过GridControl单元格的行和列索引读取它的值



我正在使用DevExpress的GridControl在不同类型的视图中显示数据。以前当我使用DataGridView时,我可以通过访问单元格值

DataGridViewObject.Rows[RowIndex].Cells[ColumnIndex/ColumnName].Value

现在,我想用GridView对象访问GridControl中相同的单元格值,但不想在Rows循环中访问这样的行,也不想在获取RowIndex和ColumnIndex的单元格单击事件中访问,因为我需要在应用程序的全局区域中维护这两个值,这样我就可以使用此语法直接获取特定的单元格值。

您可以使用GridView的GetRowCellValue方法,该方法将采用行索引和字段名或GridColumn实例来返回值。

例如:

var cellValue = myGridView.GetRowCellValue(5, "EmployeeName");

另请参阅:

读取和修改代码中的单元格值

您应该使用以下内容:

private void BindData()
{
bs = new BindingSource();
bs.DataSource = _Supplier.Select();
gcSupplier.DataSource = bs;
txtCode.DataBindings.Add("Text", bs, colCode.FieldName);
txtName.DataBindings.Add("Text", bs, colName.FieldName);
txtAddress.DataBindings.Add("Text", bs, colAddress.FieldName);
txtNationalCode.DataBindings.Add("Text", bs, colNationalCode.FieldName);
txtEconomicCode.DataBindings.Add("Text", bs, colEconomicCode.FieldName);
txtPostalCode.DataBindings.Add("Text", bs, colPostalCode.FieldName);
txtTelNumber.DataBindings.Add("Text", bs, colTelNumber.FieldName);
txtFaxNumber.DataBindings.Add("Text", bs, colFaxNumber.FieldName);
txtMobileNumber.DataBindings.Add("Text", bs, colMobileNumber.FieldName);
txtEmail.DataBindings.Add("Text", bs, colEmail.FieldName);
luePersonType.DataBindings.Add("EditValue", bs, colPersonType_Id.FieldName);
lueState.DataBindings.Add("EditValue", bs, colState_Id.FieldName);
lueCity.DataBindings.Add("EditValue", bs, colCity_Id.FieldName);
}

最新更新