Forum > Databases

"autosize" of IBDinamicGrid - header

(1/2) > >>

Nicole:
How can I get the width of the cell to fit the header?
see screenshot

dsiders:

--- Quote from: Nicole on November 29, 2022, 08:44:27 pm ---How can I get the width of the cell to fit the header?
see screenshot

--- End quote ---

Did you set a Width for those column definitions in the Columns property? It is used as a minimum width, even when AutoSizeColumn is enabled.

KodeZwerg:

--- Quote from: Nicole on November 29, 2022, 08:44:27 pm ---How can I get the width of the cell to fit the header?
see screenshot

--- End quote ---
You can call this method to calculate needed space for your elements but you need to rethink about your doing by adding more checks since on some of your columns the cell content is larger than your header text is long.

Example (not using your control but it works same way with any control)

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses .... LCLIntf, LCLType;  // calculate exact size of needed space for a control on screenfunction TextToRect(const AText: String; const AFont: TFont): TRect;var  bmp: TBitmap;  R: TRect;begin  bmp := TBitmap.Create;  try    bmp.SetSize(1, 1);    bmp.Canvas.Font.Assign(AFont);    R := Rect(0, 0, 0, 0);    DrawText(bmp.Canvas.Handle, PChar(AText), Length(AText), R, DT_CALCRECT or DT_SINGLELINE);    Result := R;  finally    bmp.Free;  end;end; { TForm1 } procedure TForm1.Button1Click(Sender: TObject);var  r: TRect;begin  r := TextToRect(Panel1.Caption, Panel1.Font);  // r has now the exact size, so you should add some space on your own, like for border...  Panel1.Width := r.Width;  Panel1.Height := r.Height;end;
On picture you see what is happening

Nicole:
Thank you for the answers.

I will try it without owner-draw if I can avoid it, maybe there is something basic wrong.
This columns property was set to zero and the fields empty (I have an IBQuery with fills the DynamicGrid at runtime).

After I tried to add something at design time and clicked "add fields" (I am not sure and do not want to try it again), the Lazarus IDE set goodbye to me with thunder and fog.

In Delphi there was a field for DBGrid, which allowed me to choose "all query fields". Such a function I have not found in Lazarus / DynamciGrid. So may be, there is something very substantial missing in my code.

Please forgive me, if I mix up menues, queris and data-components.
This looks all similar to me.

KodeZwerg:
Maybe you misunderstood my method, it has nothing to do with OwnerDrawn, just iterate over your columns headers, take caption and set calculated width for it.

Navigation

[0] Message Index

[#] Next page

Go to full version