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

[Solved] Unable to swap 2 RadGrid columns

1 Answer 187 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gary
Top achievements
Rank 2
Gary asked on 18 Jan 2010, 06:40 AM

I'm trying to swap 2 columns within the RadGrid ColumnCreated event (see code below).  When I step through the code with the debugger, it appears to be working, but when the page renders, the columns are not swapped.  I have 2 columns in the markup (update & delete links) and a number of other columns that are auto-generated.  I'm trying to swap the 2nd column in the markup with the last auto-generated column.  Why are the columns not swapping?  TIA, Gary.

        protected void rgContacts_ColumnCreated(object sender, Telerik.Web.UI.GridColumnCreatedEventArgs e)  
        {  
            switch (e.Column.UniqueName)  
            {  
                case "PartyId":  
                case "GUID":  
                case "Code":  
                case "Type":  
                    e.Column.Visible = false;  
                    break;  
                case "LastColumn":  
                    GridColumn gcDelete = rgContacts.MasterTableView.Columns.FindByUniqueName("DeleteCommand");  
                    if (gcDelete != null)  
                        e.OwnerTableView.SwapColumns(e.Column, gcDelete);  
                    e.Column.Visible = false;  
                    break;  
            }  
 

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 18 Jan 2010, 08:48 AM
Hello Gray,

The SwapColumns() method accepts either the UniqueNames or the indexes for the two columns to swap as arguments. Check out the following code which illustrtaes the SwapColumns method:
aspx:
protected void rgContacts_PreRender(object sender, EventArgs e)  
    {          
        rgContacts.MasterTableView.SwapColumns("LastColumn""DeleteCommand");  
    }  

Also refer to the following document to understand better:
Reordering columns

Thanks
Princy.
Tags
Grid
Asked by
Gary
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Share this question
or