FNCGrid HideColumn problem

If we hide a column using Grid.HideColumn(x), the events do not skip the hided column. Example: if we hide the column 3, the column 3 should not any more trigger events because the actual visible column 3 is actualy the column 4 and should trigger event for the column 4 as it is on AdvStringGrid. Is it an error or I'm wrong ?

I'm not sure what you mean with "events do not skip hided column".

Do you mean: event column indexes should take the hidden columns (not) in account?
In general, the idea is that the column index is the column display index where one typically needs to deal with things like pixel coordinates, position, ... and with the real column index where one typically needs to deal with cell data (so that the column coordinate can be used directly with accessing grid.Cells[col,row]. 

Finally, if you do not wan to deal with the difference between real & display column coordinates, you can use grid.SuppressColumn() instead of grid.HideColumn(). Then there is only one way of column indexing.

Yes, this is what I mean, event column indexes should not take the hidden columns in account. But I found the function Grid.DisplToRealColumn(acol) which makes the job.

Thanks for your help

Hello Bruno,

I used the 1st Grid Demo provided in the demo folder.

I m on Lazarus 2.0.12. Windows 10 x64 target. fpc 3.2.0.

Take a llok at my tests below :
i just added a few buttons in the form1 of the demo project.

here are the results :

procedure TForm1.Button1Click(Sender: TObject);
TMSFNCGrid1.HideColumn(3); // Hide the last column of the grid but not the 4th.

procedure TForm1.Button2Click(Sender: TObject);
// OK the "hidden" column (so the last one of the grid) is displayed again...

procedure TForm1.Button3Click(Sender: TObject);
// Display blank lines or displayed lines are "very small" after scrolling (i've screenshots and video if you want)

procedure TForm1.Button4Click(Sender: TObject);
TMSFNCGrid1.AutoSizeGrid(false); // display is not better than before, but not smart at all.

procedure TForm1.Button5Click(Sender: TObject);
TMSFNCGrid1.AutoSize:= false; // No effect

procedure TForm1.Button6Click(Sender: TObject);
TMSFNCGrid1.AutoSize:= true; // => Generate infinite loop in procedure TControl.AdjustSize;

The AutoSize property is automatically coming from the TCustomControl base class. This property should not be used. AutoSizeGrid(True) should provide better results. You can apply a default ColumnWidth & RowHeight by using the following code:

procedure TForm29.Button1Click(Sender: TObject);
  c: Integer;
  r: Integer;

  for c := 0 to TMSFNCGrid1.ColumnCount - 1 do
    TMSFNCGrid1.ColumnWidths[c] := Max(TMSFNCGrid1.ColumnWidths[c], TMSFNCGrid1.DefaultColumnWidth);

  for r := 0 to TMSFNCGrid1.RowCount - 1 do
    TMSFNCGrid1.RowHeights[r] := Max(TMSFNCGrid1.RowHeights[r], TMSFNCGrid1.DefaultRowHeight);


Hello Pieter,

The demo we used is here : TMS FNC UI Pack\Demos\LCL\Grid\Database\MemDataSet

1/ problem with Autosize :
Why not using simply and only TMSFNCGrid1.AutoSizeGrid(true) method and having to use code in addition ?

2 / problem with hiding column. Do you have a solution for this major point ?

Thank you Pieter.

We'll see what can be done for the minimum size of rows and columns when auto-sizing. For the column hiding, this is not compatible with a databound grid. You need to exclude fields that you want to hide from the grid by manually adding columns. You can manually add columns by setting AutoCreateColumns to false, and then do TMSFNCGridDatabaseAdapter.Columns.Add.FieldName := 'MyFieldName';

suggestion for the documentation : should explain this fact and limitation.