2017-07-11 31 views
1

在TcxGridDBtableview中单击标题列标题时,将自动按该列进行分组。我不想那样,我想要那个专栏的订单。在devexpress中单击标题列时禁用分组tcxgrid vcl

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

+0

不[相同](https://documentation.devexpress.com/WindowsForms/DevExpress.XtraGrid.Columns.OptionsColumn.AllowSort.property)存在用于VCL控制?对于每一列,将“OptionsColumn.AllowSort”设置为“False”? – Victoria

+0

你描述的是默认行为。 –

回答

0

只需点击标题,并禁用你不需要的属性。

enter image description here

1

由于@Uli格哈特提到的,你想要的行为是什么TcxDBGridTableView会做开箱。您必须改变行为,可能改变视图的

OptionsCustomize.GroupBySorting 

这将使正是你描述一下。从DevEx帮助:

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

语法

属性GroupBySorting:Boolean;

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

请注意,如果通过代码进行排序,GroupBySorting选项不起作用。

GroupBySorting属性的默认值为False。

+0

谢谢无! OptionsCustomize.GroupBySorting是邪恶! 已解决 – NizamUlMulk

0

在下面的代码,SetUpGrid取消已设置在cxGridDBTableView任何分组, 使列排序和排序上的名称列中的视图。

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; 
相关问题