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

bug when exporting radgridview with gridviewcomboboxcolumn

3 Answers 77 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Val
Top achievements
Rank 1
Val asked on 06 Feb 2012, 06:01 PM
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

3 Answers, 1 is accepted

Sort by
0
Val
Top achievements
Rank 1
answered on 07 Feb 2012, 09:54 AM
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
0
Pavel Pavlov
Telerik team
answered on 07 Feb 2012, 04:18 PM
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 >>
0
Val
Top achievements
Rank 1
answered on 08 Feb 2012, 10:24 AM
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
Tags
GridView
Asked by
Val
Top achievements
Rank 1
Answers by
Val
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Share this question
or