kzdown
asked on
resaze DBGrid to fit displayed columns.
I want to make dbgrid(also parent form) to fit columns shown there.
i have followng code :
==========================
procedure TTableForm.FormShow(Sender
var
www,i :Integer;
begin
www:=0;
for I := 0 to DBGrid1.Columns.Count - 1 do // Iterate
begin
www:=www+dbgrid1.Columns[i
end; // for
if www<500 then
width:=www+50 // 50 is for scrollbar and dbIndicator column
else
width:=500;
end;
==========================
but seems it isnt work ok.
when this procedure occurs database table is already opened, so it should count columnt widths and add 50 pixels for scrollbar and indicator column. but somethng is wrong. On some table it shows more space than needed, and on some oter table it shows less width then needed. How to make this dbgrid(form) to fit exactly to displayed dbgrid clumns?
Does anyone knows how to help me?
thanks in advance.
if you want to use ur code
just change the less than with greeter than in the if statment
use this code
if www>500 then
DBGRid1.width:=www+50 // 50 is for scrollbar and dbIndicator column
else
DBGrid1.width:=500;
instead of this code
if www<500 then
width:=www+50 // 50 is for scrollbar and dbIndicator column
else
width:=500;
Mohammed
just change the less than with greeter than in the if statment
use this code
if www>500 then
DBGRid1.width:=www+50 // 50 is for scrollbar and dbIndicator column
else
DBGrid1.width:=500;
instead of this code
if www<500 then
width:=www+50 // 50 is for scrollbar and dbIndicator column
else
width:=500;
Mohammed
ASKER
dbgrid is aligned to fit form,
but however
it won;t work even for dbgrid.width.
pls try.
thanks
but however
it won;t work even for dbgrid.width.
pls try.
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hello when u r using Width only, it's mean the form width, so you have to use DBGrid1.width
your code will work fine as following:
procedure TTableForm.FormShow(Sender
var
www,i :Integer;
begin
www:=0;
for I := 0 to DBGrid1.Columns.Count - 1 do // Iterate
www:=www+dbgrid1.Columns[i
DBGrid1.Width := www + 50;
end;
Mohammed