Issue with TDBAdvGrid and HideColumn

I've noticed a problem when using HideColumn on a TDBAdvGrid following a recent upgrade of our TMS component pack (current DBAdvGrid version 2.3.8.6, previously on 2.3.6.16)

Problem can be seen by droping a TDBAdvGrid onto a form and linking to any simple query with half a dozen or so columns.

Add a button with code to refresh the query as follows:

  Query1.Close;
  DBAdvGrid1.Columns.Clear;
  OraQuery1.Open;
  DBAdvGrid1.HideColumn(3);

First click of the button opens the query and correctly shows the data, with the appropriate column hidden. On a second click, the grid is now showing incorrectly, and eventually on subsequent refreshes I get 'Grid index out of range' or 'Invalid Pointer' errors.

It looks like closing the query doesn't reset the hidden columns.

On checking NumHiddenColumns, in the old version, this is always reset to 0 after Query1.Close, however in the current version it isn't and is incremented on each refresh.



What are your settings for AutoCreateColumns / AutoRemoveColumns?

Also, when you disconnect the grid and then reconnect the dataset, try calling grid.UnHideColumnsAll before disconnecting the dataset.

Both AutoCreateColumns and AutoRemoveColumns are TRUE (in my test app I've not changed them from the default)
Yes, if I call UnhideColumnsAll before closing the query then this fixes the problem. However, that is easy in the test app, (just put it before Query1.Close) but in my application the query could be closed in several places by various events on the form and I dont really want to rely on ensuring every event that closes the query calls Unhide. I know I could use the OnBeforeClose event of the query to make the call, but the grids and queries are created on-the-fly at runtime, and it would be difficult to track which grids need processing.

Any update on a fix for this issue?

As I mentioned, please use UnhideColumnsAll before you close the dataset.

As I mentioned, this is easy to do in a simple test application, but in a
more complex application where the dataset can be closed by various
events it's harder to do. As the problem didnt exist in a previous
version of the component I would assume this is a bug and calling
UnhideColumnsAll is just a workaround.

I've tried adding some code to TDBAdvGrid.ActiveChange as shown below, which looks like it solves the problem. Perhaps you could confirm whether this change would fix the issue in all cases, or whether there is something i've overlooked?

procedure TDBAdvGrid.ActiveChange(Value: Boolean);
var ...
begin
  if Assigned(FDataLink) then
  begin
    if Assigned(FDataLink.DataSet) then
    begin
      if not FDataLink.DataSet.Active then
        FShowDefinedFields := false;
      if not FDataLink.DataSet.Active then   //new line
        UnHideColumnsAll;                              //new line
...

I added a built-in solution that will be included in the next update.

Thank you. Is the next release still due 22nd March? 

Yes