【问题标题】:How to get the first cell value of selected row of a gridview?如何获取gridview选定行的第一个单元格值?
【发布时间】:2015-09-05 05:34:39
【问题描述】:

我有几列的 Gridview。当我选择特定的 gridview 行时,我无法获得第一个单元格的值。它显示以下错误。

错误 15“System.Windows.Forms.DataGridView”不包含“Cells”的定义,并且找不到接受“System.Windows.Forms.DataGridView”类型的第一个参数的扩展方法“Cells”(是您缺少 using 指令或程序集引用?)

【问题讨论】:

    标签: c# winforms


    【解决方案1】:

    你必须这样做

    foreach (DataGridViewRow row in ... )
    

    您的迭代变量中有错误的类型。

    【讨论】:

    • 我做了那个 foreach(gvViewCustomer.SelectedRows 中的 DataGridView 行)但得到了同样的错误
    • 再看看我发布的内容。它是 DataGridViewRow 行而不是 DataGridView 行。
    • @noushadmohammed 没问题。
    • @noushadmohammed 当你找到一个帖子作为你的答案时(Mihai 的 asnwer),你可以接受这个答案,当你发现有帮助的帖子时,你可以投票 :)
    【解决方案2】:

    Mihai Caracostea 正确显示了您的问题。
    只是为了了解如何使用选定的行,请考虑以下注意事项:

    • 如果你只想选择一行,设置MultiSelect yo false
    • 检查yourGrid.SelectedRows.Count==1如果要检查是否有选定的行
    • 当您想读取选定的行值时,首先检查是否有选择然后使用yourGrid.SelectedRows[0].Cells[index of column]yourGrid.SelectedRows[0].Cells[nam of column]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-17
      • 1970-01-01
      • 2011-10-23
      • 2021-06-28
      • 2018-03-10
      相关资源
      最近更新 更多