那么有没有办法,让客户自己去调整列的宽度呢?
那么有没有办法 让列宽度、行高度 随着内容而自动变换呢:
unit Unit5; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, AdvUtil, Vcl.StdCtrls, Vcl.Grids, AdvObj, BaseGrid, AdvGrid; type TForm5 = class(TForm) Button1: TButton; Button2: TButton; AdvStringGrid1: TAdvStringGrid; Button3: TButton; Button4: TButton; Button5: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button5Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form5: TForm5; implementation {$R *.dfm} procedure TForm5.Button1Click(Sender: TObject); var I: Integer; begin AdvStringGrid1.RowCount := 50;//一共50行0..49 AdvStringGrid1.ColWidths[0] := 50;//改变第一列的宽度。 AdvStringGrid1.AddCheckBoxColumn(0);//表示这一列都需要复选框 //第0行是标题头,所以从1..49开始 for I := 1 to 49 do begin //AdvStringGrid1.AddCheckBox(0, I, False, False); //可以写在这里, 表示某个单元格 需要增加 复选框 AdvStringGrid1.Cells[1,I] := '第二列 + 第二列' + I.ToString; AdvStringGrid1.Cells[2,I] := '第三列' + I.ToString; end; AdvStringGrid1.VAlignment := vtaCenter; end; procedure TForm5.Button2Click(Sender: TObject); begin //调整所有列, 第一个参数是否调节固定列, 第二个参数 单元格里数据前台间隔的字符数 AdvStringGrid1.AutoSizeColumns(True, 5); end; procedure TForm5.Button3Click(Sender: TObject); begin //调整指定列, 第一个参数 列号 ,第二个参数 内容前后间隔字符数 AdvStringGrid1.AutoSizeCol(2, 100); end; procedure TForm5.Button4Click(Sender: TObject); begin AdvStringGrid1.AutoSizeRows(True, 5); end; procedure TForm5.Button5Click(Sender: TObject); begin AdvStringGrid1.AutoSizeRow(2, 50); end; end.