【问题标题】:How to read GridControl cell value by its row and column index如何通过行和列索引读取 GridControl 单元格值
【发布时间】:2020-07-27 02:12:42
【问题描述】:

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

访问单元格值
DataGridViewObject.Rows[RowIndex].Cells[ColumnIndex/ColumnName].Value

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

【问题讨论】:

    标签: c# devexpress devexpress-gridcontrol


    【解决方案1】:

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

    例如:

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

    另见:

    Read and Modify Cell Values in Code

    【讨论】:

      【解决方案2】:

      你应该使用如下的东西:

      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);
              }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-03-21
        • 2012-07-18
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多