Shubhit304
Shubhit304

Reputation: 301

How to read GridControl cell value by its row and column index

I am working with GridControl of DevExpress to show the data in different kinds of views. Previously when I was using DataGridView I can access the cell value by

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

Now I want to access the same cell value in GridControl with GridView object similarly but don't want to access such line in for loop of Rows and also not on cell click event where I get RowIndex and ColumnIndex because I need to maintain both these in global area of my application, so that I can use this syntax to directly fetch the particular cell value.

Upvotes: 0

Views: 2474

Answers (2)

Ali NajafZadeh
Ali NajafZadeh

Reputation: 51

you should use something like follow:

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

Upvotes: 0

Brendon
Brendon

Reputation: 1259

You can use the GridView's GetRowCellValue method which will take a row index and field name or GridColumn instance to return a value.

For instance:

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

See also:

Read and Modify Cell Values in Code

Upvotes: 3

Related Questions