I am new to delphi :). I have made a simple app that is able to write and read from SQL server database. I am displaying query results in DBGrid.
Currently, I have only 3 columns in my DB (ID, Name, Surname). DBGrid displays them in a waz that I dont like. I can see ID (its width is accurate) and Name, which is stretched all the way to the right, so I have to use horizontal scrollbar to see Surname, which is also extremely wide.
How can I tell DBGrid to adjust width of columns to the widest row?
My app looks like this:
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
ADOQuery1.SQL.Text := 'INSERT INTO [dbo].[client] ([Meno],[Priezvisko]) ' +
'VALUES(:Meno, :Priezvisko)';
ADOQuery1.Parameters.ParamByName('Meno').Value := Edit1.Text;
ADOQuery1.Parameters.ParamByName('Priezvisko').Value := Edit2.Text;
ADOQuery1.ExecSQL;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ADOQuery2.SQL.Text := 'SELECT * FROM [dbo].[client] WHERE Meno = :Meno';
ADOQuery2.Active := True;
ADOQuery2.Parameters.ParamByName('Meno').Value := Edit1.Text;
ADOQuery2.ExecSQL;
end;
end.
I have found this TUTORIAL but according to this, you have t double click on chosen coumn to adjust its width, and I had also problems with this line
ColumnWidthHelper.MaxWidth := Max(ColumnWidthHelper.MaxWidth, DBGrid1.Canvas.TextWidth(Column.Field.DisplayText)) ;
It is not recognizing the Max function
Any help would be appreciated :)