devexpress gridView.Rows?

问题描述 投票:4回答:9

我想用Devexpress扩展(gridview)做到这一点:

string dataInCell = dataGridView1.Rows[i].Cells[j].Value.ToString();

喜欢 :

gridView1.Rows[i].Cells[j]
c# gridview datagridview devexpress gridcontrol
9个回答
7
投票

如果您尝试获取特定行中单元格的值,请按以下步骤操作:

一个。如果您想要焦点行的单元格的值:

view.GetFocusedRowCellValue("fieldName");

湾如果你想知道他的句柄的行的单元格值:

view.GetRowCellValue(rowHandle, "fieldName");

祝好运


5
投票

试试这个

 for (int i = 0; i < gridView.RowCount; i++)
        {
            dataInCell = Convert.ToString(gridView.GetRowCellValue(i, "FieldName"));
        }

1
投票

要获取特定行,您可以使用这些命令。

GridView.GetDataRow(rowHandle)

要么

GridView.GetRow(rowHandle)

但是如果你想修改一系列单元格,通常最好直接去数据源


1
投票

你可能在网格上设置了datasource?如果是这样,请使用数据源并通过其datasource索引访问它。

在对网格进行排序时,使用行句柄可能会导致问题。我建议...

int dataIndex = gridView.GetDataSourceRowIndex(rowHandle);
var myData = myDataSource[dataIndex];

如果您使用的是通用集合,则不会涉及转换,这会处理分组和排序。当然显示的内容和数据可能不一样。例如。如果数据是枚举。您将显示此显示名称,但数据源中的值是枚举。通常我需要基础值而不是显示的文本。


0
投票

你可以使用下面的代码:

dataGridView1.GetRowValues(dataGridView1.FocusedRowIndex,"column1-name","column2-name",...);

使用这个你可以获得聚焦于它的行索引的值,并选择字段的名称,返回值对象的类型,并转换为int,string和...这样:

string id=(string)dataGridView1.GetRowValues(dataGridView1.FocusedRowIndex,"column1-name");

但这取决于键入column1-name


0
投票
string dataInCell = ((DataRowView)gridControl1.MainView.GetRow(i)).Row.ItemArray[j].ToString();

0
投票

我想你正在寻找这个:

string str = gridView1.GetRowCellValue(Convert.ToInt32("ROW_NUMBER"), "COLUMN_NAME").ToString();

0
投票

你应该使用GetRowCellValue

string cellValue;
cellValue = gridView1.GetRowCellValue(2, "ID").ToString();

0
投票

以上所有步骤都可以,但请记住,null值会话将引发错误,因此在访问之前它会执行Convert.IsDBNull()。

© www.soinside.com 2019 - 2024. All rights reserved.