This is a migrated thread and some comments may be shown as answers.

Export to excel show class name - using MVVM

2 Answers 41 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Yuk
Top achievements
Rank 1
Yuk asked on 09 Sep 2011, 11:24 AM
When we click the export to excel, the file display class name as follows. Any idea?

System.Windows.Controls.ContentControl
MyNameSpace.Model.LoanReport
MyNameSpace.Model.LoanReport
MyNameSpace.Model.LoanReport

We inject MVVM model using MEF


 Sample of gridview xaml

<telerik:RadGridView x:Name="GridLoans" Grid.Row="1" AutoGenerateColumns="False" ShowGroupPanel="False"
                    IsFilteringAllowed="True" FontSize="10" ItemsSource="{Binding LoanListCollection}" d:DesignHeight="300"
                     ShowColumnFooters="True"  IsReadOnly="True" MaxHeight="600"
                                  >
                <telerik:RadGridView.Columns>
                  
                    <telerik:GridViewDataColumn  SortMemberPath="GroupCode" Width="100">
                        <telerik:GridViewDataColumn.Header>
                            <ContentControl>
                                <StackPanel Orientation="Vertical">
                                    <TextBlock Text="Group Id" HorizontalAlignment="Left" />
                                </StackPanel>
                            </ContentControl>
                        </telerik:GridViewDataColumn.Header>
                        <telerik:GridViewDataColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Path=GroupCode}" VerticalAlignment="Center" TextTrimming="WordEllipsis"
                                        HorizontalAlignment="Left" />
                            </DataTemplate>
                        </telerik:GridViewDataColumn.CellTemplate>
                    </telerik:GridViewDataColumn>
    </telerik:RadGridView.Columns>
         </telerik:RadGridView>

  public class LoanReport
    {
        private int Id {get;set;}

        public string GroupCode { get; set; }
    }

 

ViewModel injected with MEF

[PartCreationPolicy(CreationPolicy.NonShared)]
    [Export(Constants.ViewModel, typeof(ViewModelBase))]
    public class LoanReportViewModel : ViewModelBase
    {

 ....

   private ObservableCollection<LoanReport> loanListCollection;

        /// <summary>
        /// Loan Collection
        /// </summary>
        public virtual ObservableCollection<LoanReport> LoanListCollection
        {
            get
            {
                if (loanListCollection == null)
                {
                    loanListCollection = new ObservableCollection<LoanReport>();
                }

                UpdateQuaterPayment(loanListCollection);

                return loanListCollection;
            }

            set
            {
                loanListCollection = value;
               RaiseCollectionChange();
            }
        }

     }

2 Answers, 1 is accepted

Sort by
0
Yuk
Top achievements
Rank 1
answered on 09 Sep 2011, 11:42 AM
Looks like I need to create the DataMemberBinding

what about the header?
0
Vlad
Telerik team
answered on 12 Sep 2011, 07:11 AM
Hi,

 For custom header and templates you can use ElementExporting event and set desired value to e.Value similar to this demo

All the best,
Vlad
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
GridView
Asked by
Yuk
Top achievements
Rank 1
Answers by
Yuk
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or