【问题标题】:Disable grouping when click header column in DevExpress's VCL TcxGrid在 DevExpress 的 VCL TcxGrid 中单击标题列时禁用分组
【发布时间】:2017-07-11 00:12:21
【问题描述】:

单击标题列标题时,TcxGridDBtableView 会自动按该列分组。我不要那个,我想按那一栏排序。

我希望它在通过菜单访问时按该列分组(TcxGridPopupMenu-> 按此列分组)。

【问题讨论】:

  • VCL 控件不存在the same 吗?对于每一列,将OptionsColumn.AllowSort 设置为False?
  • 你描述的是默认行为。

标签: delphi devexpress vcl tcxgrid


【解决方案1】:

正如@Uli Gerhardt 所提到的,您想要的行为是TcxDBGridTableView 开箱即用的行为。你一定改变了行为,可能改变了视图的

OptionsCustomize.GroupBySorting

这将完全实现您所描述的。来自 DevExpress 帮助:

指定按列排序数据是否会导致按此分组 柱子。

语法

属性 GroupBySorting:布尔值;

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

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

GroupBySorting 属性的默认值为 False。

【讨论】:

  • 谢谢零! OptionsCustomize.GroupBySorting 是邪恶的!已解决
【解决方案2】:

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

【讨论】:

    【解决方案3】:

    在下面的代码中,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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多