【问题标题】:How to get values of cells of selected row in datagrid in vb.net如何在vb.net的datagrid中获取选定行的单元格的值
【发布时间】:2013-01-15 13:40:59
【问题描述】:

我试图从数据网格中选定行的单元格中获取值,但徒劳无功。我已经能够在 Windows 窗体中的 datagridview 中轻松地做到这一点,但在 wpf datagrid 中同样不起作用。到目前为止我尝试过的代码如下:

    `If Me.mileGrd.Items.Count > 0 Then
        If Me.mileGrd.SelectedItems.Count > 0 Then
            MessageBox.Show("check me")
            Dim cnum As String = Me.mileGrd.SelectedItems(0).Cells("Car No").Value
            'do more stuff here
        End If
    End If`

mileGrd 是数据网格。 当我运行程序时,我收到一条错误消息 Public member 'Cells' on type 'DataRowView' not found 。在这种情况下,我可以用什么来读取数据网格中选定行的单元格值,并将列标题作为参数,如Car No?任何帮助表示赞赏。

【问题讨论】:

    标签: vb.net wpfdatagrid


    【解决方案1】:
    Dim cnum = From row in mileGrd.Rows.Cast(Of DataGridViewRow)()
    Select row.Cells("Car No").Value 
    

    【讨论】:

    • 感谢您的回复。使用该代码时出现错误。你确定它有效吗?也许解释一下。首先我看到DataGridViewRow,但我正在使用DataGrid
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-22
    • 2013-04-04
    • 1970-01-01
    • 1970-01-01
    • 2014-01-14
    • 2014-08-29
    • 1970-01-01
    相关资源
    最近更新 更多