【问题标题】:VB.NET Linq: How to search Row ID from checkbox in DatagridviewVB.NET Linq:如何从 Datagridview 中的复选框中搜索行 ID
【发布时间】:2015-09-22 06:24:45
【问题描述】:

您好,我目前正在学习 Linq 和 VB.NET

如果选中复选框(另一个列),我正在尝试构建搜索行 ID 的 Linq

例如,我可以不用 linq Cells(15) 是数据网格视图中的复选框 并且 Cells(0) 是唯一的行 ID COL...

 For Each row As DataGridViewRow In DataGridView1.Rows
            If row.Cells(15).Value = True Then
                MsgBox(row.Cells(0).Value.ToString)
            End If
        Next

我试图从

中了解其他人在做什么

SELECT Unique rows from Datagridview using LINQ

DataGridView cell search using a LINQ query

但是,我不太确定如何根据 Linq 搜索特定 COL 中的复选框以在另一个 COL 中查找行 ID....

有人知道怎么做吗?

谢谢

【问题讨论】:

  • 是否存在 DGV 用作数据源的基础数据类型?使用它可能更容易。
  • @OneFineDay 感谢您的帮助。 row.Cells(15) 是复选框类型,而 row.Cells(0) 只是字符串类型。而其他列只是不影响这个问题的字符串。 (我的意思是我只是为其他列生成随机字符串,这意味着没有数据源..)
  • 抱歉,我的意思是有一些类型(类)的集合绑定到数据源吗?或者怎么填?

标签: .net vb.net linq datagridview


【解决方案1】:

正如问题cmets中提到的@OneFineDay,通常最好查询用作网格数据源的底层数据,但您应该能够执行以下操作:

' Not sure what type the IDs are!
Dim ids As IEnumerable(Of Integer) =
    From row As DataGridViewRow In DataGridView1.Rows
    Where CBool(row.Cells(15).Value) = True
    Select CInt(row.Cells(0).Value)
For Each id As Integer In ids
    MsgBox(CStr(id))
Next

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-16
    • 2018-06-23
    • 2018-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-26
    • 1970-01-01
    相关资源
    最近更新 更多