"autosize" of IBDinamicGrid - header lazarus / 16-Databases ---------------------------------------------------------------------- Nicole · 2022-11-29 19:44 How can I get the width of the cell to fit the header? see screenshot ---------------------------------------------------------------------- dsiders · 2022-11-29 20:35 Quote from: Nicole on November 29, 2022, 08:44:27 pmHow can I get the width of the cell to fit the header? see screenshot 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 · 2022-11-29 21:23 Quote from: Nicole on November 29, 2022, 08:44:27 pmHow can I get the width of the cell to fit the header? see screenshot 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  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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 · 2022-11-30 17:53 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 · 2022-11-30 18:02 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. ---------------------------------------------------------------------- Nicole · 2022-12-01 14:30 @KodeZwerg, DOES IT? Oh yes, I misunderstood it. I will save it and keep it for the next step in my software on the ToDo list. Thank you so much for it!! If it works for me, then it is something, what I needed since a long time. This has only worked half in Delphi as well. ---------------------------------------------------------------------- tonyw · 2022-12-01 23:02 Quote from: Nicole on November 29, 2022, 08:44:27 pmHow can I get the width of the cell to fit the header? see screenshot The objective of TIBDynamicGrid is to ensure that the coulmns always fit the grid even when it is dynamically resized at run time. At design time you set the nominal width of each column. You also nominate one or more columns to be autosized. These columns are then dynamically resized to fit the current grid width and are resized in proportion to their original width. ---------------------------------------------------------------------- Nicole · 2022-12-02 12:18 The column widths are not-adjustd at runtime. I fill them by "select * from tbanytable". What does not adjust are the headers = the field names. What may be the reason? Can the overall width be too small for it? Some table field names are not too short chosen years ago and not to change without huge effort. If the DBGrid-width would be too small for all headers / field names, I rather would prefer the whole DBGrid to be scrolled. ---------------------------------------------------------------------- tonyw · 2022-12-02 12:54 Quote from: Nicole on December 02, 2022, 01:18:00 pmThe column widths are not-adjustd at runtime. I fill them by "select * from tbanytable". What does not adjust are the headers = the field names. What may be the reason? Can the overall width be too small for it? Some table field names are not too short chosen years ago and not to change without huge effort. If the DBGrid-width would be too small for all headers / field names, I rather would prefer the whole DBGrid to be scrolled. Are you using the IDE fields editor to add the field definitions to your form? You must do this if you are to specify the width of each column and which are dynamically sized. Look at the IBX employee example and see how the columns are set up in the example. ---------------------------------------------------------------------- Nicole · 2022-12-02 18:15 The employee example does not open for me, because the database does not open in my VM. Can you pls give me a verbose hint to "the IDE fields editor" There are a lot of field editors for columns. I tried. But did not find the correct one, of crashed on attempting to use it. Maybe the whole feed of the Dynamic grid is not appropriate: I have a datacource, a dataset and an IBUpdateSQL. I am puzzled not on checking, can I have it done without query? I seemed have to have added my SQL to dataset. and: Yes, it works as such, I can use the DBNavigator and change values in my db.