Category / Section
How to extract the entire data for particular column in WinForms GridControl?
1 min read
Extract entire data
The values of a specific column can be obtained by using DrawCellDisplayText event. This event occurs for every cell before the grid draws the display text for the specified cell. But you have a limitation here, this event gets triggered only when the cell is in view state. In this sample we have added the second columns value to a list box control using button click.
The rows which are not came into the view will not be added into the list. So, iteration would be the only way to get the values other cells which are not viewable.
C#
void grid_DrawCellDisplayText(object sender, GridDrawCellDisplayTextEventArgs e) { if (e.ColIndex == 2 && e.RowIndex > 0 && !list1.Contains(e.DisplayText)) { list1.Add(e.DisplayText); } }
VB
Private Sub grid_DrawCellDisplayText(ByVal sender As Object, ByVal e As GridDrawCellDisplayTextEventArgs) If e.ColIndex = 2 AndAlso e.RowIndex > 0 AndAlso (Not list1.Contains(e.DisplayText)) Then list1.Add(e.DisplayText) End If End Sub
Samples:
C#: ExtractData_C#
VB: ExtractData_VB