Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
180
Changing FieldGroupByMode at run time with rightclick / context menu
posted

Hello!

In my WPF application I got the following xamDataGrid

<igWPF:XamDataGrid Name="DataGridTable" Theme="Office2k7Blue" AutoFit="False" FieldChooserOpening="DataGridTable_FieldChooserOpening">
<igWPF:XamDataGrid.FieldLayoutSettings>
<igWPF:FieldLayoutSettings AllowClipboardOperations="Copy" HighlightAlternateRecords="False" FilterAction="Hide" AllowAddNew="False" AllowDelete="False" HeaderPrefixAreaDisplayMode="FieldChooserButton">
</igWPF:FieldLayoutSettings>
</igWPF:XamDataGrid.FieldLayoutSettings>

<igWPF:XamDataGrid.FieldSettings>
<igWPF:FieldSettings AllowEdit="True" AllowGroupBy="True" AllowRecordFiltering="False" AllowSummaries="True"
SummaryUIType="MultiSelect" SummaryDisplayArea="BottomFixed"
LabelClickAction="SortByMultipleFieldsTriState"
LabelTextAlignment="Center" CellContentAlignment="LabelAboveValueAlignCenter"
LabelTextWrapping="Wrap" AllowLabelVirtualization="True" AutoSizeOptions="Label"
AutoSizeScope="RecordsInView" CellClickAction="SelectCell"/>
</igWPF:XamDataGrid.FieldSettings>

<igWPF:XamDataGrid.FieldLayouts>
<igWPF:FieldLayout Key="FieldLayout">

</igWPF:FieldLayout>
</igWPF:XamDataGrid.FieldLayouts>
</igWPF:XamDataGrid>

If any of the columns / fields I am adding contains a date, I am setting the FieldGroupByMode in my code behind to FieldGroupByMode.Date:

DataGridTable.FieldLayouts[0].Fields[newField.Index].Settings.GroupByMode = FieldGroupByMode.Date;

But sometimes it is necessary to change the FieldGroupByMode for a single column / field to FieldGroupByMode.Hour or anything else at runtime. 

Is there any possibility to rightclick on a column / field and then change the FieldGroupByMode?

Parents
No Data
Reply
  • 34430
    Verified Answer
    Offline posted

    Hello Nicolas,

    For this, I would recommend writing a Style for a few different elements, depending on where you would like your user to be able to click in order to change the FieldGroupByMode at runtime. The elements that you could write a style for here are CellValuePresenter or LabelPresenter. These elements have a ContextMenu property that you can set, and these elements represent the presenters for the cells and field header, respectively.

    By writing a ContextMenu for these elements in a style, you can give your style a key and apply your style to the Field.Settings.CellValuePresenterStyle or Field.Settings.LabelPresenterStyle. Then, for each menu item, you can have a click event or command that changes the GroupByMode of the corresponding field.

    To get the corresponding field, you can cast the sender of your menu item click event to a MenuItem and traverse up its Parent structure until you get to the ContextMenu element that you have placed. The ContextMenu should have a PlacementTarget property which will return the LabelPresenter or CellValuePresenter that the context menu is placed on. Both of these elements have a Field property that you can use to get the field that you are changing the group by mode on. You can then set the corresponding FieldGroupByMode to your field.

    If your field is already grouped, this change of mode will not be reflected immediately. I would recommend that you check your Field's IsGroupBy property for true, and if this condition holds true, you can get the FieldLayout that owns the Field via the Field's Owner property. I would then recommend you look for a FieldSortDescription object in the SortedFields of that FieldLayout in order to find one that has its Field property set to your field. You can then remove that FieldSortDescription from your FieldLayout.SortedFields collection and then re-add it to have the group-by mode reflected in the UI of your application.

    I have attached a sample project to demonstrate the above. I hope this helps you.

    Please let me know if you have any other questions or concerns on this matter.

    Sincerely,
    Andrew
    Associate Developer

    XDGGroupByModeRuntimeCase.zip
Children