Category / Section
How to access the cell values for all the selected rows in WinForms GridControl?
1 min read
Accessing the cell values for selected rows
To access the cell values of the selected records, get the GridRangeInfoList of the selected rows. By using the list, loop through the range to get the fields.
C#
private void btnGetCellValue_Click(object sender, EventArgs e) { GridRangeInfoList list = this.gridControl1.Selections.GetSelectedRows(true, false); foreach (GridRangeInfo range in list) { for (int i = range.Top; i <= range.Bottom; i++) for (int j = 1; j <= this.gridControl1.Model.ColCount; j++) { //Prints the text in the output screen. Trace.WriteLine(this.gridControl1[i, j].Text); } } }
VB
Private Sub btnGetCellValue_Click (ByVal sender As Object, ByVal e As EventArgs) Dim list As GridRangeInfoList = Me.gridControl1.Selections.GetSelectedRows(True, False) For Each range As GridRangeInfo In list For i As Integer = range.Top To range.Bottom For j As Integer = 1 To Me.gridControl1.Model.ColCount 'Prints the text in the output screen. Trace.WriteLine(Me.gridControl1(i, j).Text) Next j Next i Next range End Sub
Figure 1: GridControl with selected records
Figure 2: Output screen
Samples:
VB:
GetSelectedRowValues