Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Select All Rows in DbGrid

3,100 views
Skip to first unread message

Sheila L. Nelson

unread,
Jan 28, 1999, 3:00:00 AM1/28/99
to
How can I programmatically select all rows in a DbGrid when a user
clicks a button?

Thanks in advance,
Sheila Nelson

Mike Orriss

unread,
Jan 28, 1999, 3:00:00 AM1/28/99
to
In article <36B0C897...@atgl.spear.navy.mil>, Sheila L. Nelson
wrote:

> How can I programmatically select all rows in a DbGrid when a user
> clicks a button?
>

One method would be to emulate SelectAll by changing the background
color of the cells via ownerdraw.

Mike Orriss (m...@3kcc.co.uk)
http://www.3kcc.co.uk/notetree.htm


Sheila L. Nelson

unread,
Jan 29, 1999, 3:00:00 AM1/29/99
to
Can I assume that if I did it that way the grid control wouldn't
recognize those rows as selected? What I need is to give the user a
select all option and then let them manually deselect a few so they have
a quick and easy way to select say 80 out of 100 rows in a grid without
having to manually select each one. Is there a better way to do this?

Sheila

Mike Orriss

unread,
Jan 29, 1999, 3:00:00 AM1/29/99
to
In article <36B1BB6C...@atgl.spear.navy.mil>, Sheila L. Nelson
wrote:

> Can I assume that if I did it that way the grid control wouldn't
> recognize those rows as selected?

Yes

> What I need is to give the user a
> select all option and then let them manually deselect a few so they have
> a quick and easy way to select say 80 out of 100 rows in a grid without
> having to manually select each one. Is there a better way to do this?

An alternative is to offer an Invert button so they just select the ones
that they don't want and then you toggle the records.

Herminio Rodriguez

unread,
Jan 30, 1999, 3:00:00 AM1/30/99
to
Try this--it works for me. Make sure your grid is multiselect in the grid's
options. You can also select or deselect individual records by holding down
the control key and select/deselect records in the grid. Hope this helps.

procedure TfrmMain.mnuEditSelectAllClick(Sender: TObject);
begin
with DBGrid1.Datasource.Dataset do
begin
BM := Bookmark;
DisableControls;
try
First;
while not eof do
begin
DBGrid1.SelectedRows.CurrentRowSelected := True;
next;
end;
finally
Bookmark := BM;
EnableControls;
end
end;
end;

procedure TfrmMain.mnuEditSelectNoneClick(Sender: TObject);
begin
with DBGrid1.Datasource.Dataset do
begin
BM := Bookmark;
DisableControls;
try
First;
while not eof do
begin
DBGrid1.SelectedRows.CurrentRowSelected := False;
next;
end;
finally
Bookmark := BM;
EnableControls;
end
end;
end

Herminio

Sheila L. Nelson wrote in message <36B1BB6C...@atgl.spear.navy.mil>...


>Can I assume that if I did it that way the grid control wouldn't

>recognize those rows as selected? What I need is to give the user a


>select all option and then let them manually deselect a few so they have
>a quick and easy way to select say 80 out of 100 rows in a grid without
>having to manually select each one. Is there a better way to do this?
>

>Sheila
>
>Mike Orriss wrote:
>
>> In article <36B0C897...@atgl.spear.navy.mil>, Sheila L. Nelson


>> wrote:
>> > How can I programmatically select all rows in a DbGrid when a user
>> > clicks a button?
>> >
>>
>> One method would be to emulate SelectAll by changing the background
>> color of the cells via ownerdraw.
>>

Sheila L. Nelson

unread,
Feb 1, 1999, 3:00:00 AM2/1/99
to
Thanks for the tips. I'll play around with it a little and see what works out
the best.

Sheila

Mike Orriss wrote:

> In article <36B1BB6C...@atgl.spear.navy.mil>, Sheila L. Nelson


> wrote:
> > Can I assume that if I did it that way the grid control wouldn't
> > recognize those rows as selected?
>

> Yes


>
> > What I need is to give the user a
> > select all option and then let them manually deselect a few so they have
> > a quick and easy way to select say 80 out of 100 rows in a grid without
> > having to manually select each one. Is there a better way to do this?
>

> An alternative is to offer an Invert button so they just select the ones
> that they don't want and then you toggle the records.
>

0 new messages