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

Export functionality of RadGridView does not have all columns in the resulting csv

3 Answers 78 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Zach
Top achievements
Rank 1
Zach asked on 01 Mar 2012, 10:50 AM
Hi,

I am relatively new to Siliverlight and have been trying to make use of it since some time.
I have a Telerik grid (RadGridView) and was trying to export the grid rows to excel (as csv).
However, if I use a "GridViewColumn", I do not get that column in the exported list.
What could be wrong? please help....

e.g...
<UserControl x:Class="SilverlightApplication48.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    xmlns:local="clr-namespace:SilverlightApplication48"
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"             
    d:DesignHeight="300" d:DesignWidth="400">
    <UserControl.Resources>
        <local:ColorConverter x:Key="cnv" />
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <telerik:RadGridView x:Name="testGrid" AutoGenerateColumns="False">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Name}"/>

                <telerik:GridViewDataColumn Header="Rank" DataMemberBinding="{Binding Rank}">
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Rank}"/>
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                </telerik:GridViewDataColumn>

                <telerik:GridViewColumn Header="Place"
                                            IsReorderable="False"
                                            IsFilterable="False"
                                            UniqueName="MyPlace">
                    <telerik:GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Place}" />
                        </DataTemplate>
                    </telerik:GridViewColumn.CellTemplate>
                    <telerik:GridViewColumn.CellEditTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding Place}"/>
                        </DataTemplate>
                    </telerik:GridViewColumn.CellEditTemplate>
                </telerik:GridViewColumn>


            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
        <Button Content="Export" Click="Button_Click" Grid.Row="1"/>
    </Grid>
</UserControl>

3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 01 Mar 2012, 12:47 PM
Hi,

 Indeed only the bound columns (that inherit GridViewColumnBase) are exported, not the GridViewColumn. You could use a bound GridViewDataColumn. Then it will be exported successfully.

Greetings,
Didie
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Zach
Top achievements
Rank 1
answered on 01 Mar 2012, 01:15 PM
Hi Didie,

Thank you so much for your time. I created a sample in my previous post as I was not able to copy the original source code that I am working on. In that case, say if I have my column as below:

                    <telerik:GridViewColumn Header="Logged In User"
                                            IsReorderable="False"
                                            IsFilterable="False"
                                            UniqueName="LoggedInUser">
                        <telerik:GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding SelectedContact.FullName}" />
                            </DataTemplate>
                        </telerik:GridViewColumn.CellTemplate>
                        <telerik:GridViewColumn.CellEditTemplate>
                            <DataTemplate>
                                <ComboBox ItemsSource="{Binding UserContacts}"
                                          IsEnabled="{Binding HasUsersBeenLoaded}"
                                          SelectedItem="{Binding SelectedUserContact, Mode=TwoWay}"
                                          DisplayMemberPath="FullName" />
                            </DataTemplate>
                        </telerik:GridViewColumn.CellEditTemplate>
                    </telerik:GridViewColumn>

In this case, I show a textblock when the cell is not in edit mode. When the user clicks the cell, a combo box lists all the usernames
and any one from the list could be selected. All I want is, if I export the data now, I would like this column to be part of the csv file.
How can I change this code? Will replacing "Telerik:GridViewColumn" to a "GridViewDataColumn" solve it?

Sorry if this sounds silly, I haven't used these controls much and I really appreciate you taking the time to answer my query.

best regards,
Zach
0
Dimitrina
Telerik team
answered on 02 Mar 2012, 09:11 AM
Hi Zach,

 Yes, you should use the GridViewDataColumn. If you bind it, the bound value will be exported. Otherwise, you should modify your exported document in the GridView.ElementExporting event, by manipulating the value that is currently being exported.

All the best,
Didie
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
GridView
Asked by
Zach
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Zach
Top achievements
Rank 1
Share this question
or