Quantcast
Channel: Code, Snippets & Scripts – DevAdmin Blog
Viewing all articles
Browse latest Browse all 91

Ricerca in una DataGridView tramite Linq #2

$
0
0

Nel post Ricerca in una DataGridView tramite Linq avevo illustrato alcune query Linq che possono tornare utili per ottenere collection di row di una DataGridView non esposte nativamente.

Sempre tramite Linq è ad esempio possibile ottenere la collection delle celle di una determinata colonna, nell’esempio seguente la query Linq per ottenere le celle della collonna colID della DataGridView grdMain:

Dim celleColonna = (From r In Me.grdMain.Rows
Select DirectCast(r, System.Windows.Forms.DataGridViewRow).Cells).Select(
Function(c) c.Item(Me.colID.Index))

Il codice può poi essere utilizzato per creare un Extension Method che aggiunga agli oggetti  DataGridView un metodo GetColumnCells e un metodo GetColumnSelectedCells:

<System.Runtime.CompilerServices.Extension()>
Public Function GetColumnCells(ByVal grid As System.Windows.Forms.DataGridView, column As System.Windows.Forms.DataGridViewColumn) As System.Collections.Generic.IEnumerable(Of System.Windows.Forms.DataGridViewCell)
Return (From r In grid.Rows
Select DirectCast(r, System.Windows.Forms.DataGridViewRow).Cells).Select(
Function(c) c.Item(column.Index))
End Function

<System.Runtime.CompilerServices.Extension()>
Public Function GetColumnSelectedCells(ByVal grid As System.Windows.Forms.DataGridView, column As System.Windows.Forms.DataGridViewColumn) As System.Collections.Generic.IEnumerable(Of System.Windows.Forms.DataGridViewCell)
Return grid.GetColumnCells(column).Where(Function(c) c.Selected)
End Function


Viewing all articles
Browse latest Browse all 91

Trending Articles


mayabang Quotes, Torpe Quotes, tanga Quotes


Pokemon para colorear


Girasoles para colorear


Dibujos de animales para imprimir


Tropa Quotes


RE: Mutton Pies (frankie241)


Hagibis (1946) by Francisco V. Coching


Ka longiing longsem kaba skhem bad kaba khlain ka pynlong kein ia ka...


Vimeo 3.41.0 by Vimeo Inc


Vimeo Create - Video Maker & Editor 1.4.2 by Vimeo Inc