Board index » delphi » : Multiselect for DBGrid

: Multiselect for DBGrid

Given a DBGrid with Multiselect = True.
How can I access the multiple selected rows ?

The only way I found is to subclass TDBGrid and publish
the protected Bookmarks method....

best regards

Christian

 

Re:: Multiselect for DBGrid


Quote
Christian Hidber wrote:

> Given a DBGrid with Multiselect = True.
> How can I access the multiple selected rows ?

> The only way I found is to subclass TDBGrid and publish
> the protected Bookmarks method....

> best regards

> Christian

This is how I do it. BTW: The comments are i Norwegian, but don't mind
them.

 with grdDokGruppe.SelectedRows do
      if Count > 0 then
      begin
           BokMerke:= grdDokGruppe.Datasource.DataSet.GetBookMark;
           for wTeller:=0 to Count -1 do
           begin
                if IndexOf(Items[wTeller]) > -1 then
                begin

grdDokGruppe.Datasource.DataSet.BookMark:=Items[wTeller];
                     // Dersom dette dokumentet ikke finnes i valg
Kvalitetsomr?de
                     // legger man det inn. Dersom finnes fra f?r,
hopper over
                     if Not
dmData.tblDokKval.Locate('DokumentID;Kvalitetsomr',

VarArrayOf([grdDokGruppe.Datasource.DataSet.Fields[0].AsString,txtKvalomr.text]),                  
[loPartialKey]) then
                     begin
                          dmData.tblDokKval.Insert;

dmData.tblDokKval.FieldValues['DokumentID']:=grdDokGruppe.Datasource.DataSet.Fields[0].AsString;

dmData.tblDokKval.FieldValues['Kvalitetsomr']:= txtKvalomr.text;
                          dmData.tblDokKval.Post;
                     end;
                end;
           end;
      end;

This works for me.
RBS

Re:: Multiselect for DBGrid


Quote
> Given a DBGrid with Multiselect = True.
> How can I access the multiple selected rows ?

> The only way I found is to subclass TDBGrid and publish
> the protected Bookmarks method....

If you want to access the rows, the following example might help:

  Table1.Bookmark := DBGrid1.SelectedRows.Items[x];

where x is the selected item index and DBGrid1 is connected to Table1's
datasource.  Assigning Table1.Bookmark to DBGrid1.SelectedRows.Items[x]
moves Table1 to the appropriate record.  Look in the help at the Bookmark
property of TTable (new for D2, I think).  SelectedRows is a public
property of TDBGrid and is accessible without subclassing.

You might also check out my post to William J. Sky regarding
selected/unselecting all records in a grid.

MP

Re:: Multiselect for DBGrid


Quote
Christian Hidber wrote:

> Given a DBGrid with Multiselect = True.
> How can I access the multiple selected rows ?

There is a TI in the borland delphi web page that tells you how to do
it.

Roger Hernandez

Other Threads