简体   繁体   中英

Delphi, expand grouped by grid by default

I have this procedure for a grid in Delphi, and I need to add this property to expand all collapsed grouped by data in the grid.

procedure TProjectForm.dxDBGridEventDrawCell(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin
  inherited;
 DrawHighlight(ACanvas);
 TcxGridDbTableView.ViewData.Expand(True);
end;

I get the following error:

E2233 Property 'ViewData' inaccessible here

Help is appreciated please. And I also need to remove the collapsible button for the grouped data in this grid. Thank you

You can call cxGrid1DBTableView1.ViewData.Expand(True) without problems as long as you don't do in in a drawing event like the one in your q. However, you don't actually need to do this if you use the example below.

This works fine

procedure TDevexGroupingForm.FormCreate(Sender: TObject);
begin
  cxGrid1DBTableView1.Columns[2].GroupIndex := 0;  //  group by the 3rd column
  //  NOTE:  this step is only necessary if the table view has not been grouped at design-time

  cxGrid1DBTableView1.DataController.Options := cxGrid1DBTableView1.DataController.Options
   + [dcoGroupsAlwaysExpanded];  // this hides the +/- buttons of the grouped nodes

  cxGrid1DBTableView1.DataController.FocusedRowIndex := 0;  // focuses the first group
end;

Note : This has been updated at @Nil's suggestion.

  • The first line, setting a column's GroupIndex is only necessary if the TableView has not already been grouped at design time.

  • Setting the FocusedRowIndex is optional, depending on how you want the TableView to display initially

  • So in fact the hiding of the +/- grouping buttons and the expansion of all the top-level group nodes can be achieved by the single step of setting the DataController Options property to include the dcoGroupsAlwaysExpanded option.

Btw Setting the DataController options to suppress the drawing of the expand/collapse buttons and is derived from the article https://www.devexpress.com/Support/Center/Question/Details/Q105527/how-do-i-hide-the-expand-button-on-a-grid

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM