vb.net - DataGridView cell search using a LINQ query -
i'm still relatively new linq, , have done more stumbling around anything, have liked have seen far. in mind, have vb.net search routine, part of provided, below, checks text cells in datagridview given string (inclusive), using basic set of nested loops perform search:
' search first occurrence of given string each row datagridviewrow in dgvmembers.rows ' skip new row if row.isnewrow exit ' loop through cells in current row each cell datagridviewcell in row.cells ' skip non-text cells if cell.gettype isnot gettype(datagridviewtextboxcell) continue ' search our matching text if cell.value.tostring.toupper.contains(searchtext) ' select cell if have match dgvmembers.currentcell = cell writemessage("string '{0}' found.", searchtext) exit sub end if next next ' if point, didn't find writemessage("string '{0}' not found.", searchtext)
pretty straightforward. now, question is: there way replicate behavior using linq? query select (or return) first datagridviewcell text contains search string. i've done tinkering sub-queries , like, i'm still having trouble wrapping brain around concepts (too many years of writing t-sql, guess).
obviously nested loop works fine, more of curiosity, really. in advance!
i able use code success:
dim qry = therow datagridviewrow in dgvmembers.rows, _ thecell datagridviewcell in therow.cells _ thecell.value.tostring.toupper = searchtext _ select thecell dim matchcell datagridviewcell = qry.first dgvmembers.currentcell = matchcell
... etc...
Comments
Post a Comment