Thursday, October 30, 2008

Multiselection in DBGrid

1.Set dgMultiSelect option of DBGrid to true and put next code to the Button.OnClick event:

procedure TForm1.Button1Click(Sender: TObject);
var
X: Word;
TempBookmark: TBookMark;
begin
with DBGrid1.DataSource.DataSet do
begin
DisableControls;
with DBGrid1.SelectedRows do
if Count<&gt0 then
begin
TempBookmark:=GetBookmark;
for X:=0 to Count-1 do
begin
if IndexOf(Items[X])&gt-1 then
begin
Bookmark:=Items[X];
ShowMessage(Fields[1].AsString);
end;
end;
end;
GotoBookmark(TempBookmark);
FreeBookmark(TempBookmark);
EnableControls; end; end;