I want to do it with Devexpress extension (gridview) :
string dataInCell = dataGridView1.Rows[i].Cells[j].Value.ToString();
Like :
gridView1.Rows[i].Cells[j]
I want to do it with Devexpress extension (gridview) :
string dataInCell = dataGridView1.Rows[i].Cells[j].Value.ToString();
Like :
gridView1.Rows[i].Cells[j]
If you are trying to get the value of a cell in a specefic row, here is how :
a. If you want the value of a cell of the focused row :
view.GetFocusedRowCellValue("fieldName");
b. If you want the cell value of a row knowing his handle :
view.GetRowCellValue(rowHandle, "fieldName");
Good luck
try this
for (int i = 0; i < gridView.RowCount; i++)
{
dataInCell = Convert.ToString(gridView.GetRowCellValue(i, "FieldName"));
}
To get a spescific row you can use these commands.
GridView.GetDataRow(rowHandle)
or
GridView.GetRow(rowHandle)
but if you want to modify a range of cells, it is usually better to go directly at the datasource
You presumably have set a datasource
on the grid? If so, use the datasource and access it via its datasource
index.
Using row handles could causes issues when the grid is sorted. I recommend...
int dataIndex = gridView.GetDataSourceRowIndex(rowHandle);
var myData = myDataSource[dataIndex];
Provided you're using a generic collection there is no casting involved and this handles grouping and sorting. Of course what is displayed and what is the data may not be the same thing. E.g. If the data is an enumeration. You would display the displayname for this but the value in the datasource is the enum. Normally I need the underlying value instead of the displayed text.
you can use below code:
dataGridView1.GetRowValues(dataGridView1.FocusedRowIndex,"column1-name","column2-name",...);
with this you can get value with row index that focused on it and select with field`s name,return value type of object and you cast to int,string and ... such :
string id=(string)dataGridView1.GetRowValues(dataGridView1.FocusedRowIndex,"column1-name");
but it depends to type column1-name
string dataInCell = ((DataRowView)gridControl1.MainView.GetRow(i)).Row.ItemArray[j].ToString();
I think you are looking for this:
string str = gridView1.GetRowCellValue(Convert.ToInt32("ROW_NUMBER"), "COLUMN_NAME").ToString();
you should use GetRowCellValue
string cellValue;
cellValue = gridView1.GetRowCellValue(2, "ID").ToString();
All above step you can, but keep in mind that null values conversation will be thrown an error, so before access it do Convert.IsDBNull().
I think it's the best code for get row column field.
string name= gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "name").ToString(),
You can get the value of grid cell using
string cellValue = gvGrid.GetRowValues(visibleIndex, "FieldName").ToString();
where visibleIndex is the row's index. You can just loop like this
if (gvGrid.VisibleRowCount > 0)
{
for (int index = 0; index < gvGrid.VisibleRowCount; index++)
{
string cellValue = gvGrid.GetRowValues(index, "FieldName").ToString();
}
}