0

Hello I am currently studying Linq and VB.NET

I am trying to build Linq which searching row ID if checkbox is check (another col)

for example, I am able to do without linq Cells(15) is Checkbox in the data grid view and Cells(0) is unique row 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

and I was trying to follow what other people are doing from

SELECT Unique rows from Datagridview using LINQ

DataGridView cell search using a LINQ query

however, I am not really sure how I can search checkbox where are in specific COL to find Row ID in another COL based on Linq....

Does anybody know how to do it ?

thanks

Community
  • 1
  • 1
Bob Ma
  • 197
  • 5
  • 11
  • 22
  • Is there an underlying datatype that the DGV is using as a datasource? It might be easier to use that. – OneFineDay Sep 21 '15 at 20:51
  • @OneFineDay thanks for your helping. row.Cells(15) is checkbox type and row.Cells(0) is just String type. And other Cols are just string which doesn't affect to this questions. ( i mean I just generate random string for other cols which mean there is no Datasource..) – Bob Ma Sep 21 '15 at 21:04
  • Sorry, I mean is there an collection of some type(class) that is being bound to the datasource? Or how do you fill it? – OneFineDay Sep 21 '15 at 21:36

1 Answers1

0

As @OneFineDay mentioned in the question comments, it is usually better to query the underlying data used as the datasource for the grid, but you should be able to do something like this:

' 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
Mark
  • 8,140
  • 1
  • 14
  • 29