【问题标题】:devexpress gridView.Rows?devexpress gridView.Rows?
【发布时间】:2012-07-15 00:45:18
【问题描述】:

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

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

喜欢:

gridView1.Rows[i].Cells[j]

【问题讨论】:

  • 欢迎来到stackoverflow。请澄清你的问题。目前尚不清楚,您要实现什么目标。

标签: c# gridview datagridview devexpress gridcontrol


【解决方案1】:

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

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();
   }
}

【讨论】:

    【解决方案2】:

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

    string name= gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "name").ToString(),
    

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        【解决方案4】:

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

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

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

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

        【讨论】:

          【解决方案5】:

          你应该使用GetRowCellValue

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

          【讨论】:

            【解决方案6】:

            我想你正在寻找这个:

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

            【讨论】:

              【解决方案7】:
              string dataInCell = ((DataRowView)gridControl1.MainView.GetRow(i)).Row.ItemArray[j].ToString();
              

              【讨论】:

                【解决方案8】:

                你可以使用下面的代码:

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

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

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

                但这取决于输入column1-name

                【讨论】:

                  【解决方案9】:

                  试试这个

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

                  【讨论】:

                    【解决方案10】:

                    如果您尝试获取特定行中单元格的值,方法如下:

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

                    view.GetFocusedRowCellValue("fieldName");
                    

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

                    view.GetRowCellValue(rowHandle, "fieldName");
                    

                    祝你好运

                    【讨论】:

                      【解决方案11】:

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

                      GridView.GetDataRow(rowHandle)
                      

                      GridView.GetRow(rowHandle)
                      

                      但是如果你想修改一个单元格范围,通常最好直接进入数据源

                      【讨论】:

                        猜你喜欢
                        • 1970-01-01
                        • 1970-01-01
                        • 1970-01-01
                        • 1970-01-01
                        • 1970-01-01
                        • 1970-01-01
                        • 2023-02-10
                        • 2019-02-19
                        • 2017-01-07
                        相关资源
                        最近更新 更多