Articles in this section
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

 

GridControl with selected records

Figure 1: GridControl with selected records

Display the selected rows data in output window

Figure 2: Output screen

Samples:

C#: GetSelectedRowValues

VB:

GetSelectedRowValues

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied