bug when exporting radgridview with gridviewcomboboxcolumn

4 posts, 0 answers
  1. Val
    Val avatar
    5 posts
    Member since:
    Feb 2012

    Posted 06 Feb 2012 Link to this post

    Hi,

    Here is my problem, I have a radgridview with two columns (x and y for example).
    For x :

     

    <telerikGridView:GridViewDataColumn Header="aHeader" DataMemberBinding="{Binding NAME}" Width="Auto" IsReadOnly="True" />
    and for y :
    <telerikGridView:GridViewComboBoxColumn UniqueName="Uniquename" Header="anotherHeader" Width="*" 
                                                            ItemsSourceBinding="{Binding ListConfigurationsOrderByIndexWithNullConf}"                                                                       
                                                            DisplayMemberPath="NAME"
                                                            DataMemberBinding="{Binding SelectedConfiguration}"
                                                            >
                        <telerikGridView:GridViewComboBoxColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding SelectedConfiguration.NAME}" />
                            </DataTemplate>
                        </telerikGridView:GridViewComboBoxColumn.CellTemplate>
                    </telerikGridView:GridViewComboBoxColumn>

    everything works well, but when I'm exporting the radgridview into xls, for y column I only have the values of what is displaying on the screen. In other words, my radgridview has a scrollbar because there are a lot of elements, but only the rows i can see on the screen are taken into account for exporting whereas I want all to be exported.
    Sorry for my English and thanks in advance,

    Val
  2. Val
    Val avatar
    5 posts
    Member since:
    Feb 2012

    Posted 07 Feb 2012 Link to this post

    more details :

    I have this function call when exporting :
    private void radgridview_Exporting(object sender, GridViewElementExportingEventArgs e)
            {
                if (e.Context != null)
                {
                    if (e.Element == ExportElement.Row)
                    {
                        _confToExport = (A_STRUCTURE)((GridViewRow)e.Context).Item;
                    }
                    else if (e.Element == ExportElement.Cell && e.Context is GridViewComboBoxColumn)
                    {
                        if (_confToExport.SelectedConfiguration != null)
                        {
                              e.Value = _confToExport.SelectedConfiguration.NAME;
                        }
                    }
                }
            }

    The problem occurs for  if(e.Element == ExportElement.Row), only visible rows on the screen are taken into account (whereas for example, all ExportElement.Cell are).
    I tried different approaches to solve my problem but I cant find any solutions...
    Val
  3. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 07 Feb 2012 Link to this post

    Hello Valentin,

     
    Indeed RadGridView would traverse the visual tree in order to get the exported result as close to what you see as possible.  By default it has the row virtualization turned on . This provides a great scrolling performance boost as only the elements visible in the viewport are considering for rendering , databinding etc.

    To have all the elements realized ( not only the ones in the viewport) you will need to turn off the row virtualization e.g. this.RadGridView1.EnableRowVirtualization = false;
    An alternative would be to place RadGridView into a panel that would measure it with infinity e.g. a stack panel ( vertical).

    All the best,
    Pavel Pavlov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  4. Val
    Val avatar
    5 posts
    Member since:
    Feb 2012

    Posted 08 Feb 2012 Link to this post

    I also find a solution to solve my problem by changing my code like that :
    private void radgridview_Exporting(object sender, GridViewElementExportingEventArgs e)
            {
                if (e.Element == ExportElement.Row)
                {
                    _confToExport = (A_STRUCTURE)e.Value;
                }
                else if (e.Element == ExportElement.Cell
                    && e.Context is GridViewComboBoxColumn)
                {
                    if (_confToExport.SelectedConfiguration != null
                        && _confToExport.SelectedConfiguration.ID != -1)
                    {
                        e.Value = _confToExport.SelectedConfiguration.NAME;
                    }
                }
            }
    Thank you for your fast answer which also works very well, but I prefer enable row virtualisation ;).

    Have a nice day,

    Val
Back to Top