Export example not working.

13 posts, 0 answers
  1. William
    William avatar
    29 posts
    Member since:
    Sep 2016

    Posted 27 Jan Link to this post

    I tried to implement the Export functionality for GridView shown in the UI for WPF example (Word, Excel, CSV export), and I get everything to work except that the "context" is incorrect. When I get into the code, the object that is passed as a parameter is the high-level parent of the GridView I would like to export. What am I doing wrong that I can't get the "context" parameter to be correct?

    XAML:

        xmlns:exp="clr-namespace:GridView.Exporting"
        <UserControl.Resources>
            <exp:ExportingModel x:Key="context" />

     

        <telerik:RadButton x:Name="ExpGPData" Content="Export" Grid.Column="0" ToolTip="Export this data to an Excel format" Command="{Binding ExportCommand, Source={StaticResource context}}" CommandParameter="{Binding}"/>

     

    ExportingModel.cs is same as in the example.

  2. Stefan X1
    Admin
    Stefan X1 avatar
    578 posts

    Posted 01 Feb Link to this post

    Hi William,

    I tested the referred demo locally, and it seems to be working as expected. May I kindly ask you to shed some light on the context not being correct? Is the ExportCommand in the ExportingModel triggered on your end?

    Thank you in advance for your cooperation.

    Regards,
    Stefan X1
    Telerik by Progress
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  3. William
    William avatar
    29 posts
    Member since:
    Sep 2016

    Posted 01 Feb in reply to Stefan X1 Link to this post

    The code was added EXACTLY as in the WPF demos.  This is the button that exports:

    <telerik:RadButton x:Name="ExpGapAnalysis" Content="Export" Grid.Row="1" Grid.Column="6" ToolTip="This will export the Gap Analysis" Command="{Binding ExportCommand, Source={StaticResource context}}" CommandParameter="{Binding}" />

    I can trace down to the statement: public void Execute(object parameter) in the class: ExportCommand.

    The parameter is set to the class for the entire form, not for the particular grid where the button is located.

     

  4. Stefan X1
    Admin
    Stefan X1 avatar
    578 posts

    Posted 06 Feb Link to this post

    Hello William,

    Though I am not completely sure what the exact cause for such behavior might be, may I ask you to try binding the CommandParameter through ElementName?
    <telerik:RadButton Content="Export"
                                   Command="{Binding ExportCommand, Source={StaticResource context}}"
                                   CommandParameter="{Binding ElementName=RadGridView1}"
                                   Margin="0,10,0,0" />

    Is the grid now passed correctly as a parameter?

    Regards,
    Stefan X1
    Telerik by Progress
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  5. William
    William avatar
    29 posts
    Member since:
    Sep 2016

    Posted 06 Feb in reply to Stefan X1 Link to this post

    That worked to get the export functionality working. However, are you aware that the export doesn't work completely? With "SelectedExportFormat"="Excel", the headers come out without names:

     

  6. William
    William avatar
    29 posts
    Member since:
    Sep 2016

    Posted 06 Feb in reply to Stefan X1 Link to this post

    The second type of export (SelectedExportFormat="ExcelML") doesn't have the correct headers, either:
  7. Stefan X1
    Admin
    Stefan X1 avatar
    578 posts

    Posted 09 Feb Link to this post

    Hello William,

    Thank you for the provided images.

    Generally speaking, such behavior is replicated when custom Header is defined for the column. Can you please clarify whether you have applied a custom Header content? If this is the case, please, take a look at the Export Custom Header topic.

    Hopefully, it helps.

    Regards,
    Stefan X1
    Telerik by Progress
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  8. William
    William avatar
    29 posts
    Member since:
    Sep 2016

    Posted 09 Feb in reply to Stefan X1 Link to this post

    Yes, there are custom headers. I am using your example "GridView.Exporting". Where do I put the code for the header?
  9. William
    William avatar
    29 posts
    Member since:
    Sep 2016

    Posted 09 Feb in reply to Stefan X1 Link to this post

    I was able to get the header cells to display correctly. How do I get the actual raw value of the data rather than the formatted value (e.Value in method ElementExporting)?
  10. Stefan X1
    Admin
    Stefan X1 avatar
    578 posts

    Posted 14 Feb Link to this post

    Hi William,

    A possible solution for this would be to access the Header of the needed column. This can be achieved by utilizing the Columns collection of RadGridView. Would such an approach be feasible for you?

    Another approach would be to use the UniqueName property of the needed column, as its value will be corresponding to the DataMemberBinding of the column.

    I hope you find one of these suggestions useful.

    Regards,
    Stefan X1
    Telerik by Progress
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  11. William
    William avatar
    29 posts
    Member since:
    Sep 2016

    Posted 14 Feb in reply to Stefan X1 Link to this post

    I was asking about the raw data value, not the header. I have been able to get the custom header working. Where can I find the raw data value, not the formatted one?
  12. Stefan X1
    Admin
    Stefan X1 avatar
    578 posts

    Posted 17 Feb Link to this post

    Hi William,

    Thank you for this clarification.

    In this case, you will need to access the relevant property of the bound item. This can be achieved by using the DataContext of the exported row. Please, take a look at the following code snippet.
    private void gridViewExport_ElementExporting(object sender
        , GridViewElementExportingEventArgs e)
    {
        if (e.Element == ExportElement.Row)
        {
            var item = ((e.Context as GridViewRow).DataContext as Club);
             
        }
    }

    I hope this helps.

    Regards,
    Stefan X1
    Telerik by Progress
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  13. William
    William avatar
    29 posts
    Member since:
    Sep 2016

    Posted 17 hours ago in reply to Stefan X1 Link to this post

    I have been able to put in changes to get the name of the custom header. Now, the problem is with the export itself.

    When I set SelectedExportFormat="Excel", it creates an "xls" file, but when I open it in Excel, it gives me an error message.

    When I set SelectedExportFormat="ExcelML", no error message is created when I open it, but the code to get the custom header name is NOT executed.

    Is there a set of code that works completely to give custom headers but also doesn't generate an error when opening in Excel?

     

Back to Top