4

我想用 Devexpress 扩展(gridview)来做:

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

喜欢 :

gridView1.Rows[i].Cells[j]
4

11 回答 11

7

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

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

view.GetFocusedRowCellValue("fieldName");

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

view.GetRowCellValue(rowHandle, "fieldName");

祝你好运

于 2012-07-16T09:23:13.917 回答
5

尝试这个

 for (int i = 0; i < gridView.RowCount; i++)
        {
            dataInCell = Convert.ToString(gridView.GetRowCellValue(i, "FieldName"));
        }
于 2012-11-12T08:01:05.387 回答
1

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

GridView.GetDataRow(rowHandle)

或者

GridView.GetRow(rowHandle)

但是如果要修改一系列单元格,通常最好直接进入数据源

于 2012-07-16T07:46:14.183 回答
1

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

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

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

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

于 2015-12-18T23:58:10.437 回答
0
string dataInCell = ((DataRowView)gridControl1.MainView.GetRow(i)).Row.ItemArray[j].ToString();
于 2013-04-08T10:58:49.047 回答
0

您可以使用以下代码:

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

有了这个,您可以使用专注于它的行索引获取值,并使用字段的名称进行选择,返回对象的值类型,然后转换为 int、string 和 ... 这样:

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

但这取决于输入column1-name

于 2012-12-15T05:56:55.933 回答
0

你应该使用GetRowCellValue

string cellValue;
cellValue = gridView1.GetRowCellValue(2, "ID").ToString();
于 2017-04-18T17:24:28.130 回答
0

我想你正在寻找这个:

string str = gridView1.GetRowCellValue(Convert.ToInt32("ROW_NUMBER"), "COLUMN_NAME").ToString();
于 2015-10-27T10:21:36.317 回答
0

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

于 2019-04-09T09:33:19.470 回答
0

您可以使用获取网格单元格的值

string cellValue = gvGrid.GetRowValues(visibleIndex, "FieldName").ToString();

其中 visibleIndex 是行的索引。你可以像这样循环

if (gvGrid.VisibleRowCount > 0)
{
   for (int index = 0; index < gvGrid.VisibleRowCount; index++)
   {
      string cellValue = gvGrid.GetRowValues(index, "FieldName").ToString();
   }
}
于 2021-04-22T07:49:55.000 回答
0

我认为这是获取行列字段的最佳代码。

string name= gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "name").ToString(),
于 2019-10-16T10:24:37.920 回答