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
385
DataPresenterExcelExporter behaves oddly
posted

Hi,

I was wondering if you could shed any lights on the following issues that I came across with. I attached the solution to this post. In that I subscribed to almost all of the events, because I wanted to play around this a little bit.

  1. Records marked as not selected, although grid contains them in grid.SelectedItems.Records
    My goal is not to export all the rows from the grid, but the selected rows only. So, I assumed the if I subscribe to InitializeRecord I can filter out rows that are not selected. So I used e.Record.IsSelected property, but it was false all the time. Not to mention that myGrid.SelectedItems.Records[0] == e.Record was always false. So I cannot determine if the record under processing can be included or not.
  2. Empty column appeared in the excel file, when I omit a column
    I assumed that if I cancel HeaderLabelExporting and CellExporting on the given column it would help, but wouldn't. I tried to alter the fieldlayout in HeaderAreaExporting by removing the not required column, but the result was the same. There was an empty column in my result xls.
  3. Style does not get applied, but converters does
    Basically, if I have a converter on a particular column, the exported data will show the converted value, not the original one. But, if I have applied a CellValuePresenterStyle on that same column the value could be different depending on what ControlTemplate does with the data. In order to see the same, I have to amend the "real" value. Where can I do this?

Regards,
Peter

WpfExport2Excel.zip
  • 130
    Suggested Answer
    posted

    For Issue 1.

    Solution could be use following code

    below code for button event

    DataPresenterExcelExporter exporter = new DataPresenterExcelExporter();
                    if (this.dgSelectedLoans.SelectedItems.Count() == 1)
                    {
                        if (MessageBox.Show("Do you want to export selected row only?"Helper.MessageBoxHeader, MessageBoxButton.YesNoCancel) == MessageBoxResult.Yes)
                        {
                            exporter.InitializeRecord += new EventHandler<InitializeRecordEventArgs>(exporter_InitializeRecord);  
                        }
                    }
                    exporter.Export(this.dgSelectedLoans, tbExportSelectedLoans.Text,WorkbookFormat.Excel2007);
                    MessageBox.Show("File Exported"Helper.MessageBoxHeader);

    Event code.

    void exporter_InitializeRecord(object sender, InitializeRecordEventArgs e)
            {
                Record obj = e.Record.GetAssociatedRecord();
                if (!obj.IsSelected)
                {
                    e.SkipRecord = true;
                }
            }
    
    
    Regards
    Mukesh
  • 9694
    posted

    Hello,

    I apologize that no one has yet answered this post. We were inundated with more posts than we had resources to cover. Since that time we have been adding people to the task of making sure every post gets a reply from an Infragistics employee.

    Have you tried the latest version of NetAdvantage? Please let me know if you still have these issues with the newest version and I will do what I can to answer your questions.

    Sincerely,