Amazing User
Amazing User

Reputation: 3563

DevExpress: How to get value by index in gridView?

I have a GridWiew with column Status Id and table Status in database with colunms Status Id and Value.

In GridView I need to replace status number to it's value from the table.

enter image description here

How can I do it with GridView Designer? I think, there should be some property like binding source:

enter image description here

Upvotes: 0

Views: 1654

Answers (1)

Niranjan Singh
Niranjan Singh

Reputation: 18290

As a solution, you can use the BaseView.GetRow method. This method will return an object that represents your data source item. To get the item's data source index, use the ColumnView.GetDataSourceRowIndex method.

//It is just an example.. 
int dataSourceRowIndex = view.GetDataSourceRowIndex(gridView.FoucsedRowHandle);
//Let suppose you bind with datatable
dataTable.Rows[dataSourceRowIndex]["Status"]=editedValue;

You can use the FocusedRowHandle property to find the edited row. Also, you can use the CellValueChanged event and its e.RowHandle parameter.

To update values in your database, use one of the approaches described in the Post Data to an Underlying Data Source article, depending on the type of your data source.

References:
How to get an item's data source row index of the sorted grid view
Update only some details row if master row is selected

Upvotes: 1

Related Questions