在DevExpress的VCL TcxGrid中单击标题列时禁用分组

问题描述 投票:1回答:3

单击标题列标题时,TcxGridDBtableView会自动按该列分组。我不想那样,我想按那个专栏订购。

当按菜单访问时,我希望它按该列分组(TcxGridPopupMenu-> Goup by this column)。

delphi devexpress vcl tcxgrid
3个回答
1
投票

正如@Uli Gerhardt所说,你想要的行为是TcxDBGridTableView开箱即用的行为。您必须已更改行为,可能会更改视图

OptionsCustomize.GroupBySorting

这将完全符合您的描述。来自DevExpress的帮助:

指定按列对数据排序是否会导致按此列进行分组。

句法

property GroupBySorting:Boolean;

说明启用GroupBySorting选项允许您模拟MS Outlook 2003的行为。这意味着单击列标题会导致按单击列的值对数据进行分组。在这种情况下,先前应用的分组将被清除。如果禁用GroupBySorting选项,则单击列标题会导致按此列的值对数据进行排序。

请注意,如果通过代码排序,则GroupBySorting选项无效。

GroupBySorting属性的默认值为False。


0
投票

只需单击标题,然后禁用不需要的属性。

enter image description here


0
投票

在下面的代码中,SetUpGrid取消已在cxGridDBTableView上设置的任何分组,启用列排序并对Name列上的视图进行排序。

Groupby1Click方法通过设置其GroupingIndex(参见在线帮助)对代码中给定列进行分组/取消分组。

procedure TDevexGroupingForm.SetUpGrid;
var
  i : Integer;
begin
  try
    cxGrid1DBTableView1.BeginUpdate;

    //  Hide GroupBy panel
    cxGrid1DBTableView1.OptionsView.GroupByBox := False;

    //  Allow column sorting
    cxGrid1DBTableView1.OptionsCustomize.ColumnSorting := True;

    //  Undo any existing grouping e.g. set up in IDE
    for i:= 0 to cxGrid1DBTableView1.ColumnCount - 1 do begin
      cxGrid1DBTableView1.Columns[i].GroupIndex := -1;
    end;

    //  Sort TableView on Name column.  Needs 'Uses dxCore'
    cxGrid1DBTableView1Name.SortOrder := soAscending;

  finally
    cxGrid1DBTableView1.EndUpdate;
  end;

end;

procedure TDevexGroupingForm.Groupby1Click(Sender: TObject);
var
  ACol : TcxGridDBColumn;
  Index : Integer;
begin

  //  The following code operates on the focused column of a TcxGridDBTableView
  //  If the view is already grouped by that column, it is ungrouped;
  //  Otherwise, the column is added to the (initially empty) list of columns
  //  by which the view is grouped;

  Index := TcxGridTableController(cxGrid1DBTableView1.DataController.Controller).FocusedColumnIndex;
  if Index < 0 then
    exit;

  ACol := cxGrid1DBTableView1.Columns[Index];
  if ACol = Nil then
    exit;

  if ACol.GroupIndex < 0 then begin
    //  Add ACol to the list of grouped Columns
    ACol.GroupIndex := cxGrid1DBTableView1.GroupedColumnCount + 1;
  end
  else begin
    //  Ungroup on ACol
    ACol.GroupIndex := -1;
  end;
end;
© www.soinside.com 2019 - 2024. All rights reserved.