简体   繁体   中英

Resize the columns stringgrid in delphi

I want a Stringgrid. I change the size of the columns.

This Stringgrid is connected to the database. However, I tried different methods; the column did not change. What should I do?

Not sure what you mean by "lengths", ie their widths or their heights.

This code will change the lefthand column's width:

procedure TForm1.Button1Click(Sender: TObject);
begin
  SG1.ColWidths[0] := SG1.ColWidths[0] + 10;
end;

This link will show you how to "autosize" the grid's column widths:

How do I make a StringGrid's columns fit the grid's width?

In case you actually meant the heights of the cells, you can do this a row at a time like this:

procedure TForm1.btnHeightClick(Sender: TObject);
begin
  SG1.RowHeights[1] := SG1.RowHeights[1] + 10;  //  NB Row 0 is the column header
end;

Or, you can set the height of all rows at once like this:

procedure TForm1.btnHeightsClick(Sender: TObject);
begin
  SG1.DefaultRowHeight := SG1.DefaultRowHeight + 10;
end;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM