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

Add column to end of grid programatically with auto generated columns

2 Answers 526 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.
Matt Greer
Top achievements
Rank 1
Matt Greer asked on 30 Nov 2010, 05:44 PM
I have a RadGridView with AutoGenerateColumns set to true. I want to add an additional column as the last column programatically.

What event is the best event on the RadGridView to listen to for this?


RadGridView.DataLoaded does not work, as this fires before the auto generated columns are created, placing my column before them.

RadGridView.AutoGeneratingColumn does not work, as I don't know how many columns my grid will have.


The best event I've found is RadGridView.SelectionChanged, as this will get fired once the grid is fully set up. But man this feels hacky and dirty.

I wish RadGridView had an AutoGeneratedColumns event, that fired after all the auto generated columns were created.


This thread: http://www.telerik.com/community/forums/silverlight/gridview/event-to-add-column-at-the-end.aspx
has an example that uses the DataLoaded event. The problem is the grid in the sample is not using auto generated columns.




I am using Telerik Controls version 2010.2.812.1040

2 Answers, 1 is accepted

Sort by
0
Accepted
Veselin Vasilev
Telerik team
answered on 01 Dec 2010, 09:30 AM
Hi Matt Greer,

I have just tested adding of columns in the DataLoaded event and it worked correctly.
The code I used is:

private void clubsGrid_DataLoaded(object sender, EventArgs e)
{
    if (this.clubsGrid.Columns.Count > 0)
    {
        this.clubsGrid.Columns.Add(new GridViewSelectColumn()
                  {
                      DisplayIndex = this.clubsGrid.Columns.Count
                  });
    }
}

I have attached a sample project as well.

Kind regards,
Veselin Vasilev
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Matt Greer
Top achievements
Rank 1
answered on 01 Dec 2010, 05:29 PM
Ahhhh, gotcha. I wasn't checking to see if Columns.Count > 0.

This does work. Although I'd still love to see an AutoGeneratedColumns event :)
Tags
GridView
Asked by
Matt Greer
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Matt Greer
Top achievements
Rank 1
Share this question
or