Hello,
I have some of GridViewCheckBoxColumn and GridViewComboBoxColumn that bound to nested property which works perfectly. But when I try to use ExportToXlsx() to export into excel file, result from every columns that bound to nested property are different.
GridViewCheckBoxColumn bound to nested property yields True/False instead of TRUE/FALSE and GridViewComboBoxColumn yields selected value instead of display value which I preferred display value.
Is there anyway to make all columns regardless of nested property binding to be exported in the same format?
Here's my sample code
<Window x:Class="WpfApplication3.Window4" xmlns:local="clr-namespace:WpfApplication3" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" mc:Ignorable="d" Title="Window4" Width="800" Height="300" > <StackPanel> <telerik:RadGridView Name="grid1" ItemsSource="{Binding GridItemSoure}" AutoGenerateColumns="False"> <telerik:RadGridView.Columns> <telerik:GridViewDataColumn Header="Display" DataMemberBinding="{Binding Display}"/> <telerik:GridViewCheckBoxColumn Header="IsChecked" DataMemberBinding="{Binding IsChecked}"/> <telerik:GridViewComboBoxColumn Header="SelectedItem" DataMemberBinding="{Binding SelectedItemId}" ItemsSource="{Binding ComboItemSource}" DisplayMemberPath="Display" SelectedValueMemberPath="Id"/> <telerik:GridViewDataColumn Header="Amount" DataMemberBinding="{Binding Amount}"/> <telerik:GridViewDataColumn Header="This.Display" DataMemberBinding="{Binding This.Display}"/> <telerik:GridViewCheckBoxColumn Header="This.IsChecked" DataMemberBinding="{Binding This.IsChecked}"/> <telerik:GridViewComboBoxColumn Header="This.SelectedItem" DataMemberBinding="{Binding This.SelectedItemId}" ItemsSource="{Binding ComboItemSource}" DisplayMemberPath="Display" SelectedValueMemberPath="Id"/> <telerik:GridViewDataColumn Header="This.Amount" DataMemberBinding="{Binding This.Amount}"/> </telerik:RadGridView.Columns> </telerik:RadGridView> <Button Click="Button_Click">Export</Button> </StackPanel></Window>public partial class Window4 : Window{ public Window4() { InitializeComponent(); this.DataContext = new { GridItemSoure = new List<RowItem>() { new RowItem() { Display = "Row1", IsChecked = true, SelectedItemId = null, Amount = 9.999m }, new RowItem() { Display = "Row2", IsChecked = false, SelectedItemId = null, Amount = 10000 }, new RowItem() { Display = "Row3", IsChecked = true, SelectedItemId = 2, Amount = 1/3 }, new RowItem() { Display = "Row4", IsChecked = false, SelectedItemId = 3, Amount = -1/3 }, }, ComboItemSource = new List<Item>() { new Item() { Id = 1, Display = "Item 1" }, new Item() { Id = 2, Display = "Item 2" }, new Item() { Id = 3, Display = "Item 3" }, }, }; } private void Button_Click(object sender, RoutedEventArgs e) { string extension = "xlsx"; SaveFileDialog dialog = new SaveFileDialog() { DefaultExt = extension, Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, "Excel Workbook"), FilterIndex = 1 }; if (dialog.ShowDialog() == true) { using (Stream stream = dialog.OpenFile()) { grid1.ExportToXlsx(stream, new GridViewDocumentExportOptions() { ShowColumnHeaders = true, ShowColumnFooters = true, ShowGroupFooters = true, AutoFitColumnsWidth = true, ExportDefaultStyles = false, }); } } }}public class RowItem : INotifyPropertyChanged{ private string _Display; public string Display { get { return _Display; } set { this._Display = value; OnPropertyChanged(nameof(Display)); } } private bool _IsChecked; public bool IsChecked { get { return _IsChecked; } set { this._IsChecked = value; OnPropertyChanged(nameof(IsChecked)); } } private int? _SelectedItemId; public int? SelectedItemId { get { return _SelectedItemId; } set { this._SelectedItemId = value; OnPropertyChanged(nameof(SelectedItemId)); } } private decimal? _Amount; public decimal? Amount { get { return _Amount; } set { this._Amount = value; OnPropertyChanged(nameof(Amount)); } } public RowItem This { get { return this; } } public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(string name) { if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(name)); }}public class Item : INotifyPropertyChanged{ private string _Display; public string Display { get { return _Display; } set { this._Display = value; OnPropertyChanged(nameof(Display)); } } private int? _Id; public int? Id { get { return _Id; } set { this._Id = value; OnPropertyChanged(nameof(Id)); } } public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(string name) { if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(name)); }}
Thanks
