Hi,
We are using XamGrid v14.0 and using ExcelExporter to export the grid.
One of our fields uses Unbound and has a ComboBox in ControlTemplate, when exporting to Excel the value is always empty. Here is the cell in xamdatagrid:
<dataPresenter:UnboundField x:Name="Code" Label="Code"> <dataPresenter:UnboundField.Settings> <dataPresenter:FieldSettings LabelTextAlignment="Left"> <dataPresenter:FieldSettings.CellValuePresenterStyle> <Style TargetType="{x:Type dataPresenter:CellValuePresenter}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <ComboBox ItemsSource="{Binding DataItem.Parent.Codes}" DisplayMemberPath="MyCode" SelectedItem="{Binding DataItem.Code, UpdateSourceTrigger=LostFocus}" IsEnabled="{Binding DataItem.Enabled}"/> </ControlTemplate> </Setter.Value> </Setter> </Style> </dataPresenter:FieldSettings.CellValuePresenterStyle> </dataPresenter:FieldSettings> </dataPresenter:UnboundField.Settings> </dataPresenter:UnboundField>
Hello Tam,
I have been investigating into the behavior you are seeing, and I believe the issue that you are seeing is likely stemming from the underlying cell values of your “Code” UnboundField being null. With the UnboundField, the Cell.Value property needs to be set manually for each record, and the Excel export will be looking at the underlying cell values to find what to export.
With the above said, it looks like you are binding the SelectedItem of your ComboBox to the Code property on your data item, and so I’m not sure it is necessary for you to be using an UnboundField. It should be possible to change the UnboundField to a Field with a Name of “Code.” This will fill out the underlying Cell values and should allow the Excel export to work correctly.
Please let me know if you have any other questions or concerns on this matter.
Hi Andrew,
I did try it with your suggestion, now it does show up but it is displaying the object in the cell i.e. namecspace.codeDto
It sounds like the underlying value of the cell for your “Code” property is not a simple primitive object type in this case, but rather a class of your creation.
Since this is the case, I believe my best recommendation would be to handle the CellExporting event of the DataPresenterExcelExporter that I am assuming you are using to export your XamDataGrid to Excel. This event’s arguments will have information about the Field and the owning Record that owns the cell that is exporting. It also has a Value property that you can use to modify the value that you wish to be exported to Excel.