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

4 posts, 0 answers
  1. Zach
    Zach avatar
    2 posts
    Member since:
    Jun 2010

    Posted 01 Mar 2012 Link to this post

    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>
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 01 Mar 2012 Link to this post

    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 >>
  3. Zach
    Zach avatar
    2 posts
    Member since:
    Jun 2010

    Posted 01 Mar 2012 Link to this post

    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
  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 02 Mar 2012 Link to this post

    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 >>
Back to Top