To access the values of the selected rows in a grid, you must access the SelectedRows collection.
Use the following code to write each of the selected rows to the Debug window:
Dim row As Integer
For Each row In Me.C1TrueDBGrid1.SelectedRows
Debug.WriteLine(Me.C1TrueDBGrid1.Columns(0).CellValue(row))
Next
· C#
int row;
foreach (int row in this.c1TrueDBGrid1.SelectedRows)
{
Debug.WriteLine(this.c1TrueDBGrid1.Columns(0).CellValue(row));
}
· Delphi
var row: Integer;
for row := 0 to Self.C1TrueDBGrid1.SelectedRows.Count-1 do
begin
Debug.WriteLine(Self.C1TrueDBGrid1.Columns[0].CellValue(row));
end;
You can also use the grid's index to access the rows. Use the following code:
Dim row As Integer
For Each row In Me.C1TrueDBGrid1.SelectedRows
Debug.WriteLine(Me.C1TrueDBGrid1(row, 0).ToString())
Next
· C#
int row;
foreach (int row in this.c1TrueDBGrid1.SelectedRows)
{
Debug.WriteLine(this.c1TrueDBGrid1(row, 0).ToString());
}
· Delphi
Var row: Integer;
for row := 0 to Self.C1TrueDBGrid1.SelectedRows.Count-1 do
begin
Debug.WriteLine(Self.C1TrueDBGrid1[row, 0].ToString);
end;
For this example, the following code was added to the Button1_Click event in Tutorial 5 - Selecting Multiple Rows Using Bookmarks:
Dim row As Integer
For Each row In Me.C1TrueDBGrid1.SelectedRows
Debug.WriteLine(Me.C1TrueDBGrid1(row, 1).ToString())
Next
· C#
int row;
foreach (int row in this.c1TrueDBGrid1.SelectedRows)
{
Debug.WriteLine(this.c1TrueDBGrid1(row, 1).ToString());
}
· Delphi
Var row: Integer;
for row := 0 to Self.C1TrueDBGrid1.SelectedRows.Count-1 do
begin
Debug.WriteLine(Self.C1TrueDBGrid1[row, 1].ToString);
end;
This topic illustrates the following:
The Last name of each composer in a selected row is returned in the Debug window:
Send comments about this topic to ComponentOne. Copyright © ComponentOne LLC. All rights reserved. |