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

GridViewDataControl_ColumnDisplayIndexOutOfRange

4 Answers 122 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Rieni De Rijke
Top achievements
Rank 1
Rieni De Rijke asked on 09 Apr 2010, 02:56 PM
When I open an PrintPreviewDialog all works well, but...

...when I change the column-order by dragging a column to an other place, opening of the Printpreview gives an:
System.ArgumentOutOfRangeException: GridViewDataControl_ColumnDisplayIndexOutOfRange.

The same happens in your "RadControls for WPF-Demo":  GridView/WPF/Printing:
Change the column-order and click "printpreview".

4 Answers, 1 is accepted

Sort by
0
Rieni De Rijke
Top achievements
Rank 1
answered on 13 Apr 2010, 08:41 PM
My colleges have the same problem with their RadControls for WPF-Demo-Application.
Are we the only ones...?

When I open an PrintPreviewDialog all works well, but...

...when I change the column-order by dragging a column to an other place, opening of the Printpreview gives an:
System.ArgumentOutOfRangeException: GridViewDataControl_ColumnDisplayIndexOutOfRange.

The same happens in your "RadControls for WPF-Demo":  GridView/WPF/Printing:
Change the column-order and click "printpreview".
0
Vlad
Telerik team
answered on 14 Apr 2010, 02:41 PM
Hi,

Here is how to change ToPrintFriendlyGrid method in our example to fix this:
static GridViewDataControl ToPrintFriendlyGrid(GridViewDataControl source)
{
    RadGridView grid = new RadGridView();
 
    grid.ItemsSource = source.ItemsSource;
    grid.RowIndicatorVisibility = Visibility.Collapsed;
    grid.ShowGroupPanel = false;
    grid.CanUserFreezeColumns = false;
    grid.IsFilteringAllowed = false;
    grid.AutoExpandGroups = true;
    grid.AutoGenerateColumns = false;
 
    foreach (GridViewDataColumn column in source.Columns.OfType<GridViewDataColumn>())
    {
        GridViewDataColumn newColumn = new GridViewDataColumn();
        newColumn.Width = column.ActualWidth;
        newColumn.DataMemberBinding = new System.Windows.Data.Binding(column.UniqueName);
        grid.Columns.Add(newColumn);
    }
 
    foreach (GridViewDataColumn column in grid.Columns.OfType<GridViewDataColumn>())
    {
        GridViewDataColumn sourceColumn = (from c in source.Columns.OfType<GridViewDataColumn>()
                                          where c.UniqueName == column.UniqueName
                                          select c).FirstOrDefault();
        if (sourceColumn != null)
        {
            column.DisplayIndex = sourceColumn.DisplayIndex;
        }
    }
 
    StyleManager.SetTheme(grid, StyleManager.GetTheme(grid));
 
    grid.SortDescriptors.AddRange(source.SortDescriptors);
    grid.GroupDescriptors.AddRange(source.GroupDescriptors);
    grid.FilterDescriptors.AddRange(source.FilterDescriptors);
 
    return grid;
}


Greetings,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Rieni De Rijke
Top achievements
Rank 1
answered on 14 Apr 2010, 06:56 PM
Thank you for the fix!
Now it works fine.
0
Paul
Top achievements
Rank 1
answered on 17 Jan 2011, 06:42 PM
The updated code does not work unless all of your columns are data columns.  Setting the DisplayIndex of the columns fails otherwise.  The following update will work:

int i = 0;
foreach (GridViewDataColumn column in grid.Columns.OfType<GridViewDataColumn>().OrderBy(e => e.DisplayIndex))
{
   GridViewDataColumn sourceColumn = (from c in source.Columns.OfType<GridViewDataColumn>()
                                      where c.UniqueName == column.UniqueName
                                      select c).FirstOrDefault();
   if (sourceColumn != null)
   {
      column.DisplayIndex = i;
      i++;
   }
}
Tags
GridView
Asked by
Rieni De Rijke
Top achievements
Rank 1
Answers by
Rieni De Rijke
Top achievements
Rank 1
Vlad
Telerik team
Paul
Top achievements
Rank 1
Share this question
or