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

Replacing a column throws exception

4 Answers 40 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 02 Jun 2011, 10:00 AM
Hello,

I am pretty sure this used to work before.

this.radGridView.Columns[0] = new GridViewDataColumn();

Now it throws a System.IndexOufOfRange exception, message "Index was outside the bounds of the array"

My version is 2011.1.419.1040

4 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 02 Jun 2011, 10:11 AM
Hi Ken,

You need to add a column like follows:

this.RadGridView1.Columns.Add(new GridViewDataColumn(){DisplayIndex = 0});

The DisplayIndex property will define at which position the column will be displayed.
 

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
Andrew
Top achievements
Rank 1
answered on 02 Jun 2011, 10:14 AM
Thank you for the fast response.

DisplayIndex looks a bit weird to use, can you please tell what are the reasons behind this change?

0
Andrew
Top achievements
Rank 1
answered on 02 Jun 2011, 10:16 AM
I got side tracked by your answer, actually adding is not what I need. I need to replace a column. 

So going back to my original question, how can I replace a column?
0
Maya
Telerik team
answered on 02 Jun 2011, 03:44 PM
Hello Ken,

If you want to replace a column, you may remove it first and add a new only with the exact same display index:

this.clubsGrid.Columns.RemoveAt(1);
this.clubsGrid.Columns.Add(new GridViewDataColumn() { DataMemberBinding = new Binding("Name"), DisplayIndex = 1 });
 

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
Tags
GridView
Asked by
Andrew
Top achievements
Rank 1
Answers by
Maya
Telerik team
Andrew
Top achievements
Rank 1
Share this question
or