C# devexpress gridView.Rows?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11499747/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
devexpress gridView.Rows?
提问by AhmetSem
I want to do it with Devexpress extension (gridview) :
我想用 Devexpress 扩展(gridview)来做到这一点:
string dataInCell = dataGridView1.Rows[i].Cells[j].Value.ToString();
Like :
喜欢 :
gridView1.Rows[i].Cells[j]
回答by Stig
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
但是如果你想修改一个范围的单元格,通常最好直接去数据源
回答by SidAhmed
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
祝你好运
回答by Snippet
try this
尝试这个
for (int i = 0; i < gridView.RowCount; i++)
{
dataInCell = Convert.ToString(gridView.GetRowCellValue(i, "FieldName"));
}
回答by Chakavak Behzad
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 :
有了这个,您可以获得具有关注它的行索引的值,并使用字段的名称进行选择,返回对象的值类型,然后您转换为 int、string 和 ... 例如:
string id=(string)dataGridView1.GetRowValues(dataGridView1.FocusedRowIndex,"column1-name");
but it depends to type column1-name
但这取决于键入 column1-name
回答by Mehmet
string dataInCell = ((DataRowView)gridControl1.MainView.GetRow(i)).Row.ItemArray[j].ToString();
回答by Shankha Subhra Ghosh
I think you are looking for this:
我想你正在寻找这个:
string str = gridView1.GetRowCellValue(Convert.ToInt32("ROW_NUMBER"), "COLUMN_NAME").ToString();
回答by Darren G
You presumably have set a datasourceon the grid? If so, use the datasource and access it via its datasourceindex.
你大概已经datasource在网格上设置了一个?如果是这样,请使用数据源并通过其datasource索引访问它。
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.
如果您使用的是通用集合,则不涉及强制转换,这将处理分组和排序。当然,显示的内容和数据的内容可能不是一回事。例如,如果数据是枚举。您将为此显示显示名称,但数据源中的值是枚举。通常我需要基础值而不是显示的文本。
回答by Rayan Albouni
you should use GetRowCellValue
你应该使用GetRowCellValue
string cellValue;
cellValue = gridView1.GetRowCellValue(2, "ID").ToString();
回答by jigar prajapati
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().
以上所有步骤都可以,但请记住,空值对话将引发错误,因此在访问它之前执行 Convert.IsDBNull()。
回答by Md.Rezwan
I think it's the best code for get row column field.
我认为这是获取行列字段的最佳代码。
string name= gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "name").ToString(),

