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
920
Exporting Hierarchical data to excel
posted

Hi,

I have defined a context menu on my usercontrol with options to export hierarchical data to excel, top level only, checked -> hierarchical data, checked -> top level only to excel. I want to define the context menu at this level. I want to be able to pass XamDataGrid has a parameter to the command. How do I do this?

<UserControl ....

<UserControl.ContextMenu>

<MenuItem Header="ExportAll" HorizontalAlignment="Left">
<MenuItem Header="Top Level Only" Command="{Binding Path=PlacementTarget.DataContext.ExportAllToplevelCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" HorizontalAlignment="Left" />
<MenuItem Header="Export Top Level and children" Command="{Binding Path=PlacementTarget.DataContext.ExportAllTopLevelandSubLevelsCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" HorizontalAlignment="Left" />
</MenuItem>
<MenuItem Header="ExportChecked" HorizontalAlignment="Left">
<MenuItem Header="Top Level Only" Command="{Binding Path=PlacementTarget.DataContext.ExportCheckedToplevelCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" HorizontalAlignment="Left" />
<MenuItem Header="Export Top Level and children" Command="{Binding Path=PlacementTarget.DataContext.ExportCheckedTopLevelandSubLevelsCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" HorizontalAlignment="Left" />
</MenuItem>

<UserControl.ContextMenu>

<Grid>

<igDP:XamDataGrid...>

Thanks,

Lala

Parents
No Data
Reply
  • 34810
    Offline posted

    Hello Lala,

    Thank you for your post.

    From the code that you have provided, it appears that the PlacementTarget of your ContextMenu is the UserControl, and not the XamDataGrid. If you would like to continue with the UserControl as your placement target, I would recommend using the CommandParameter property of your MenuItem elements to pass the UserControl itself to your command. From there, you can use the Infragistics.Windows.Utilities class and its GetDescendantFromType method to get your XamDataGrid. The code to this would look like the following, where MyUC is the UserControl:

    XamDataGrid xdg = Infragistics.Windows.Utilities.GetDescendantFromType(MyUC, typeof(XamDataGrid), false) as XamDataGrid;

    From there, you should be able to export the XamDataGrid to Excel by following the steps shown here: http://help.infragistics.com/Help/Doc/WPF/2015.2/CLR4.0/html/xamDataPresenter_Export_a_DataPresenter_Control_to_Excel.html.

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

    Sincerely,
    Andrew
    Associate Developer
    Infragistics Inc.
    www.infragistics.com/support

Children
No Data