Recent

Author Topic: AutoSizeColumns with KDBGrid  (Read 2138 times)

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 592
    • Double Dummy Solver - free download
AutoSizeColumns with KDBGrid
« on: January 14, 2018, 08:57:02 pm »
I like the way KDBGrid scrolls but I'm having problems with other features of this component. Does anyone know how its AutoSizeColumn feature works? Isn't there some way that the column widths get adjusted?

Also - how can I define a Title at run time. This doesn't work:
   KDBGrid1.Columns[c].Title := 'a new title';
Lazarus 3.0RC2, FPC 3.2.2 x86_64-win64-win32/win64

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: AutoSizeColumns with KDBGrid
« Reply #1 on: January 14, 2018, 09:07:35 pm »
I can't find a reference for KDBgrid?
 
 but since it looks like it is a Data base grid via the name for it, I would be my guess that it
may not be allowing you to change it runtime or, it could have a bug or it would that it does not
want you to over write in once it has a data base record loaded in it...
 
 but then again, I can't find a reference to it so its only my guess that it is a data base grid?
The only true wisdom is knowing you know nothing

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 592
    • Double Dummy Solver - free download
Re: AutoSizeColumns with KDBGrid
« Reply #2 on: January 14, 2018, 10:30:09 pm »
Yes it's a grid control - part of the K-Controls. Written about 8 years ago. It's important to be able to change the title for each column at run time to accommodate other languages. A bigger concern to me is the way this component adjusts column widths
Lazarus 3.0RC2, FPC 3.2.2 x86_64-win64-win32/win64

balazsszekely

  • Guest
Re: AutoSizeColumns with KDBGrid
« Reply #3 on: January 15, 2018, 07:15:44 am »
@bobonwhidbey

I never used the component myself, but it looks OK to me. Just drop a TKGrid + TButton to your form, then:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   W: Integer;
  4.   Str: String;
  5. begin
  6.   Str := 'this is a long column title';
  7.   W := KGrid1.Canvas.GetTextWidth(Str) + 5;
  8.   KGrid1.ColWidths[1] := W; //sizing column 1
  9.   KGrid1.Cells[1, 0] := Str;
  10. end;
It works fine.

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 592
    • Double Dummy Solver - free download
Re: AutoSizeColumns with KDBGrid
« Reply #4 on: January 15, 2018, 07:44:37 am »
It's a bit trickier with the DBGrid. I've discovered that I can change the heading like this:

      TKDBGridCol(KDBGrid1.Columns[c]).Title := 'Some heading';

I had the impression that some complicated coding was contained in TKDBGrid to obtain the maximum column widths. It's impractical to read every column in every row of a large DB file to obtain the maximum width of each column.  As a simple example, assume you only have 3 columns with maximum widths of 10, 40, and 20.  If your grid has a total width of 100 pixels, I want to add equal padding to each column, ending with column widths of 20,50, and 30.

Is there an SQL command that can get those maximum widths?
Lazarus 3.0RC2, FPC 3.2.2 x86_64-win64-win32/win64

 

TinyPortal © 2005-2018