2011. április 21., csütörtök

How to retrieve selected rows in a TDBGrid


Problem/Question/Abstract:

How can I retrieve the text displayed in selected rows? Whenever I inspect the TDBGrid - SelectedRows property I find:
1) TDBGrid - SelectedRows - Count as the number of rows selected in the grid.
2) Iterating through the TDBGrid - SelectedRows - Items[i] property I get blank strings.
What should I get when I read a Bookmark?

Answer:

You try to inspect a bookmark, not the record the bookmark points to. Try this:


{ ... }
var
  i: integer;
begin
  for i := 0 to DBGrid1.SelectedRows.Count - 1 do
  begin
    Table1.GoToBookmark(TBookmark(DBGrid1.SelectedRows[i]));
    Memo1.Lines.Add(Table1.Fields[0].AsString); {process the record}
  end;
end;

Nincsenek megjegyzések:

Megjegyzés küldése