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

Index was out of range error when trying to set SortingState

2 Answers 84 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Keith
Top achievements
Rank 1
Keith asked on 12 May 2011, 09:40 PM
I have two pieces of code which do the exact same thing when populating a RadGridView, but when I try to call this on one of them:

grid.ItemsSource = data;
grid.Columns[0].SortingState = SortingState.Descending;

... it receives an error:

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index


Looking at the grid it obvious it has no columns yet (Count = 0).  I have tried Rebind() with no success.  I'm not sure why this is not working the same way the similar code is which employs the exact same technique.  The data is available and appearing without issue and AutoGenerateColumns is set to true yet the columns are not present.

Is there some event I should wait to complete once I bind before I set the SortingState?  Any thoughts on what could be causing this?

Thank you in advance. 

2 Answers, 1 is accepted

Sort by
0
Accepted
Maya
Telerik team
answered on 13 May 2011, 08:04 AM
Hi Keith,

You may add a SortDescriptor and define the Member you want to be applied to. For example:

public MainPage()
        {
            InitializeComponent();
            this.clubsGrid.SortDescriptors.Add(new SortDescriptor() { Member = "Name" });
        }


Kind regards,
Maya
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
Keith
Top achievements
Rank 1
answered on 13 May 2011, 05:59 PM
This worked despite my initial trepidation that it may not resolve the issue.

Thanks!
Tags
GridView
Asked by
Keith
Top achievements
Rank 1
Answers by
Maya
Telerik team
Keith
Top achievements
Rank 1
Share this question
or