Search code examples
delphidevexpressdelphi-xe4

cxGrid clear columns on form close


I have a grid that I use to display few query results (cxGrid1.ActiveLevel.GridView := cxGrid1DBTableView1; etc ...). On form close, I close the queries as well.

However, the former columns that were last displayed remain visible (when I return to that form again) How can I eliminate these traces of columns as well? I would like empty grid when I return to the form.

Edit : This is the query that I run :

procedure TForm2.cxRadioGroup1Click(Sender: TObject);
begin
case cxRadioGroup1.ItemIndex of
0: begin
   with Form1.UniQuery3 do begin
   Close;
   sql.Clear;
   sql.Add('select * from program_log');
   Open;
   cxGrid1.ActiveLevel.GridView := cxGrid1DBTableView1;

end;
end;
1: begin
  with Form1.UniQuery4 do begin
   Close;
   sql.Clear;
   sql.Add('select * from guests_log');
   Open;
   cxGrid1.ActiveLevel.GridView := cxGrid1DBTableView2;
end;
end;
end;
end;

Calling

cxGrid1DBTableView1.ClearItems;

Removes all traces of columns which are then unavailable if I want to run the query again.


Solution

  • Calling cxGrid1DBTableView1.ClearItems will remove all columns. Just call it in your FormClose event handler. To recreate columns call cxGrid1DBTableView1.DataController.CreateAllItems function.