Im folgenden Code, SetUpGrid
jede Gruppierung bricht auf einem cxGridDBTableView bereits eingerichtet, ermöglicht Spaltensortierung und sortiert die Ansicht auf einer Spalte Namen.
Die Groupby1Click
-Methode gruppiert/trennt die Gruppen in einer bestimmten Spalte im Code, indem Sie ihren GroupingIndex festlegen (siehe Online-Hilfe).
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;
Does not [das gleiche] (https://documentation.devexpress.com/WindowsForms/DevExpress.XtraGrid.Columns.OptionsColumn.AllowSort.property) sind für die Steuerung VCL? Setzen Sie für jede Spalte den 'OptionsColumn.AllowSort' auf' False'? – Victoria
Was Sie beschreiben, ist das Standardverhalten. –