Hi,
I am using XamDataGrid and DataPresenterExcelExporter which is exporting my fields to Excel fine except for my unbound field which is coming up with blank values. Can you please advise?
This is my code snippet:
<ipdg:Field BindingType="Unbound" Label="Cust All-In Price" Visibility="Collapsed"> <ipdg:Field.Settings> <ipdg:FieldSettings Width="Auto" CellValuePresenterStyle="{StaticResource BidAskCell}" AllowRecordFiltering="False" LabelClickAction="Nothing"/> </ipdg:Field.Settings> </ipdg:Field>
Thanks.
Hello,
Thank you for choosing Infragistics.
I have been looking into your issue and I have prepared a sample application for you to test. Please note that I was not able to reproduce the issue you have described.
Would you please provide me with more detailed information in regards to the setting of the Visibility property of the Field and the style you have used for the CellValuePresenter? Would you also please modify the sample application I have attached so the issue is reproduced and send it back to me? Having this information would help me further investigate this matter for you.
Looking forward to your reply.
Thank you for your reply. This is the BidAskCell style for the CellValuePresenter:
<Style x:Key="BidAskCell" TargetType="{x:Type igDP:CellValuePresenter}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}" >
<StackPanel x:Name="stackPanel" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Label Name="BidRate" Foreground="{StaticResource ForegroundBrush}" Margin="0" Padding="0">
<TextBlock Text="{Binding Path=Record.DataItem.NearLegPriceInCuBid, RelativeSource={RelativeSource TemplatedParent}}"/>
</Label>
<TextBlock Name="Slash" Text=" / " VerticalAlignment="Center" Foreground="{StaticResource PriceMinorDigitsForeground}" />
<Label Name="AskRate" Foreground="{StaticResource ForegroundBrush}" Margin="0" Padding="0">
<TextBlock Text="{Binding Path=Record.DataItem.NearLegPriceInCuAsk, RelativeSource={RelativeSource TemplatedParent}}"/>
</StackPanel>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding Path=DataItem.NearLegPriceInCuAsk}" Value="{x:Null}">
<Setter TargetName="Slash" Property="Visibility" Value="Collapsed"></Setter>
<Setter TargetName="AskRate" Property="Visibility" Value="Collapsed"></Setter>
</DataTrigger>
<DataTrigger Binding="{Binding Path=DataItem.NearLegPriceInCuBid}" Value="{x:Null}">
<Setter TargetName="BidRate" Property="Visibility" Value="Collapsed"></Setter>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
This is the difference between the code you sent me and my code. I don't do the assignment in C#. On the C# side, I only have:
var exporter = (DataPresenterExcelExporter) Resources["Exporter"]; exporter.Export(TradeGrid, fileName, WorkbookFormat.Excel2007);
The visibility is initially set as Collapsed but then the user can go in the Field Chooser and select the column to be displayed. When I export to Excel, there is a column called "Cust All-In Price" but the values are all empty.
Let me know if you require more information.
Thank you.
I have been looking further into your issue and please note that re-templating the CellValuePresenter with a ControlTemplate may lead to unexpected behavior and in this case the default exporting logic for certain cells is not used. In the code snippet you have provided, you have defined a few visual elements which you would like to export. This way the CellValuePresenter does not have the necessary information in regards to what should be exported as a value for the current cell, but only what to visualize and how to visualize it.
An approach I can suggest you is to use the InitializeRecord event of the XamDataGrid and to manually assign the UnboundField's cell value for each record as I have done in the sample application I have previously attached.
Another approach I can suggest you use instead of an UnboundField is to define a new property in your DataItem's class and add a new Field to your XamDataGrid by binding the new Field to the new property. The new property's value can be formatted to look as a concatenation of two of your other properties (prop1 + " / " + prop2) instead of using three TextBlocks. This way you should be able to provide a Value for each CellValuePresenter respectively and it will know what to export as a value to Excel.
If you require any further assistance on this matter, please do not hesitate to ask.
Thank you. I decided to go with the second approach. It seems to be working except I get "Number stored as text" errors when I export. Is there a way to ignore the errors code-wise?
Thank you for your feedback.
The behavior you have described is expected because the Excel itself recognizes the values with their editing type which is a string. In order to avoid the message produced by Excel you can always use the first approach and use explicitly defined numbers or change the type of the cells directly in Excel.
Thank you for your feedback. I am glad to know that I was able help you achieve the functionality you were looking for. I believe this thread can help other people looking for a similar solution.
Would be great to have a CSV Exporter in the future but for now the Excel Exporter will do. Thanks a lot for your help.
Currently, the Workbook class does not support saving and loading to and from CSV files. For more information in regards to this behavior, you can take a look at the following thread:
http://es.infragistics.com/community/forums/t/104677.aspx
If you require any further assistance on the matter, please let me know.
Thanks. Do you have a CSV exporter by any chance?