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

Column re-order problem after databind

6 Answers 387 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Glen Luettgrodt
Top achievements
Rank 1
Glen Luettgrodt asked on 09 Oct 2009, 07:50 PM
I am having a problem with the RadGridView not allowing the user to re-order the columns via column header dragging after the grid has been bound to a data source. I can click and begin to drag a column header, however once I release the mouse button, the column returns to its original position, not the position I dropped it at. This only happens after I have bound the grid to a datasource.

Am I doing something wrong or is this expected behavior?

Using GridView version 2009.2.9.729

The code below is a form with a RadGridView and 3 columns. After I click the bind button, I can no longer re-order columns:

using System;  
using System.Drawing;  
using System.Windows.Forms;  
using System.ComponentModel;  
using Telerik.WinControls.UI;  
 
namespace TelerikGridTest  
{  
    public partial class SimpleGridTest : Form  
    {  
        private Telerik.WinControls.UI.RadGridView radGridView1;  
 
        private void btnBind_Click(object sender, EventArgs e)  
        {  
            BindingList<SomeObject> data = new BindingList<SomeObject>();  
            data.Add(new SomeObject("1.1", "1.2", "1.3", "1.4"));  
            data.Add(new SomeObject("2.1", "2.2", "2.3", "2.4"));  
            data.Add(new SomeObject("3.1", "3.2", "3.3", "3.4"));  
 
            radGridView1.DataSource = data;  
            //now I can't re-order columns  
        }  
 
        private void btnUnbind_Click(object sender, EventArgs e)  
        {  
            radGridView1.DataSource = null;  
        }  
 
        public SimpleGridTest()  
        {  
            GridViewTextBoxColumn gridViewTextBoxColumn1 = new GridViewTextBoxColumn();  
            GridViewTextBoxColumn gridViewTextBoxColumn2 = new GridViewTextBoxColumn();  
            GridViewTextBoxColumn gridViewTextBoxColumn3 = new GridViewTextBoxColumn();  
            this.radGridView1 = new Telerik.WinControls.UI.RadGridView();  
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).BeginInit();  
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1.MasterGridViewTemplate)).BeginInit();  
            this.SuspendLayout();  
            this.radGridView1.Location = new System.Drawing.Point(15, 50);  
            gridViewTextBoxColumn1.FieldAlias = "Val1";  
            gridViewTextBoxColumn1.FieldName = "Val1";  
            gridViewTextBoxColumn1.HeaderText = "column1";  
            gridViewTextBoxColumn1.UniqueName = "column1";  
            gridViewTextBoxColumn1.Width = 150;  
            gridViewTextBoxColumn2.FieldAlias = "Val2";  
            gridViewTextBoxColumn2.FieldName = "Val2";  
            gridViewTextBoxColumn2.HeaderText = "column2";  
            gridViewTextBoxColumn2.UniqueName = "column2";  
            gridViewTextBoxColumn2.Width = 150;  
            gridViewTextBoxColumn3.FieldAlias = "Val3";  
            gridViewTextBoxColumn3.FieldName = "Val3";  
            gridViewTextBoxColumn3.HeaderText = "column3";  
            gridViewTextBoxColumn3.UniqueName = "column3";  
            gridViewTextBoxColumn3.Width = 150;  
            this.radGridView1.MasterGridViewTemplate.Columns.Add(gridViewTextBoxColumn1);  
            this.radGridView1.MasterGridViewTemplate.Columns.Add(gridViewTextBoxColumn2);  
            this.radGridView1.MasterGridViewTemplate.Columns.Add(gridViewTextBoxColumn3);  
            this.radGridView1.Name = "radGridView1";  
            this.radGridView1.Size = new System.Drawing.Size(600, 355);  
            Button btnBind = new Button();  
            btnBind.Text = "Bind to Data";  
            btnBind.Location = new Point(15, 15);  
            btnBind.Size = new Size(100, 25);  
            btnBind.Click += btnBind_Click;  
            this.Controls.Add(btnBind);  
            Button btnUnbind = new Button();  
            btnUnbind.Text = "Unbind from Data";  
            btnUnbind.Location = new Point(115, 15);  
            btnUnbind.Size = new Size(100, 25);  
            btnUnbind.Click += btnUnbind_Click;  
            this.Controls.Add(btnUnbind);  
            this.ClientSize = new System.Drawing.Size(630, 415);  
            this.Controls.Add(this.radGridView1);  
            this.Name = "SimpleGridTest";  
            this.Text = "SimpleGridTest";  
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1.MasterGridViewTemplate)).EndInit();  
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).EndInit();  
            this.ResumeLayout(false);  
            this.PerformLayout();  
        }  
    }  
 
    public class SomeObject  
    {  
        public SomeObject() { }  
        public SomeObject(string val1, string val2, string val3, string val4)  
        {  
            Val1 = val1;  
            Val2 = val2;  
            Val3 = val3;  
            Val4 = val4;  
        }  
        public string Val1 { get; set; }  
        public string Val2 { get; set; }  
        public string Val3 { get; set; }  
        public string Val4 { get; set; }  
    }  
}  
 

6 Answers, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 14 Oct 2009, 02:06 PM
Hello Glen Luettgrodt,

Thank you for the question. I am afraid that I could not reproduce the behavior you described; I tested RadGridView with the latest build. Please provide a small sample application that I may debug and provide a solution. I am looking forward to your reply.

Best wishes,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Glen Luettgrodt
Top achievements
Rank 1
answered on 14 Oct 2009, 04:09 PM

I supplied a sample form in my original forum post that is currently demonstrating this behavior. I have tested this code against the official 2009.2.9.729 release, as well as the 2009.2.9.903 internal build. The behavior is identical in either build. The visual location of the column does not change when using column header drag drop while the grid is databound.

Here is the code again:

using System;  
using System.Drawing;  
using System.Windows.Forms;  
using System.ComponentModel;  
using Telerik.WinControls.UI;  
 
namespace TelerikGridTest  
{  
    public partial class SimpleGridTest : Form  
    {  
        private Telerik.WinControls.UI.RadGridView radGridView1;  
 
        private void btnBind_Click(object sender, EventArgs e)  
        {  
            BindingList<SomeObject> data = new BindingList<SomeObject>();  
            data.Add(new SomeObject("1.1", "1.2", "1.3", "1.4"));  
            data.Add(new SomeObject("2.1", "2.2", "2.3", "2.4"));  
            data.Add(new SomeObject("3.1", "3.2", "3.3", "3.4"));  
 
            radGridView1.DataSource = data;  
            //now I can't re-order columns  
        }  
 
        private void btnUnbind_Click(object sender, EventArgs e)  
        {  
            radGridView1.DataSource = null;  
        }  
 
        public SimpleGridTest()  
        {  
            GridViewTextBoxColumn gridViewTextBoxColumn1 = new GridViewTextBoxColumn();  
            GridViewTextBoxColumn gridViewTextBoxColumn2 = new GridViewTextBoxColumn();  
            GridViewTextBoxColumn gridViewTextBoxColumn3 = new GridViewTextBoxColumn();  
            this.radGridView1 = new Telerik.WinControls.UI.RadGridView();  
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).BeginInit();  
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1.MasterGridViewTemplate)).BeginInit();  
            this.SuspendLayout();  
            this.radGridView1.Location = new System.Drawing.Point(15, 50);  
            gridViewTextBoxColumn1.FieldAlias = "Val1";  
            gridViewTextBoxColumn1.FieldName = "Val1";  
            gridViewTextBoxColumn1.HeaderText = "column1";  
            gridViewTextBoxColumn1.UniqueName = "column1";  
            gridViewTextBoxColumn1.Width = 150;  
            gridViewTextBoxColumn2.FieldAlias = "Val2";  
            gridViewTextBoxColumn2.FieldName = "Val2";  
            gridViewTextBoxColumn2.HeaderText = "column2";  
            gridViewTextBoxColumn2.UniqueName = "column2";  
            gridViewTextBoxColumn2.Width = 150;  
            gridViewTextBoxColumn3.FieldAlias = "Val3";  
            gridViewTextBoxColumn3.FieldName = "Val3";  
            gridViewTextBoxColumn3.HeaderText = "column3";  
            gridViewTextBoxColumn3.UniqueName = "column3";  
            gridViewTextBoxColumn3.Width = 150;  
            this.radGridView1.MasterGridViewTemplate.Columns.Add(gridViewTextBoxColumn1);  
            this.radGridView1.MasterGridViewTemplate.Columns.Add(gridViewTextBoxColumn2);  
            this.radGridView1.MasterGridViewTemplate.Columns.Add(gridViewTextBoxColumn3);  
            this.radGridView1.MasterGridViewTemplate.AllowColumnReorder = true;  
            this.radGridView1.Name = "radGridView1";  
            this.radGridView1.Size = new System.Drawing.Size(600, 355);  
            Button btnBind = new Button();  
            btnBind.Text = "Bind to Data";  
            btnBind.Location = new Point(15, 15);  
            btnBind.Size = new Size(100, 25);  
            btnBind.Click += btnBind_Click;  
            this.Controls.Add(btnBind);  
            Button btnUnbind = new Button();  
            btnUnbind.Text = "Unbind from Data";  
            btnUnbind.Location = new Point(115, 15);  
            btnUnbind.Size = new Size(100, 25);  
            btnUnbind.Click += btnUnbind_Click;  
            this.Controls.Add(btnUnbind);  
            this.ClientSize = new System.Drawing.Size(630, 415);  
            this.Controls.Add(this.radGridView1);  
            this.Name = "SimpleGridTest";  
            this.Text = "SimpleGridTest";  
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1.MasterGridViewTemplate)).EndInit();  
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).EndInit();  
            this.ResumeLayout(false);  
            this.PerformLayout();  
        }  
    }  
 
    public class SomeObject  
    {  
        public SomeObject() { }  
        public SomeObject(string val1, string val2, string val3, string val4)  
        {  
            Val1 = val1;  
            Val2 = val2;  
            Val3 = val3;  
            Val4 = val4;  
        }  
        public string Val1 { get; set; }  
        public string Val2 { get; set; }  
        public string Val3 { get; set; }  
        public string Val4 { get; set; }  
    }  
}  
 
0
Victor
Telerik team
answered on 19 Oct 2009, 02:30 PM
Hello Glen Luettgrodt,

I copied and pasted the code you provided and I tested again with build x.x.x.903. The order works as usual. Please note that if you have adjacent columns and assuming you want to change the left column to be on the right side, you have to drop the left column to the right of the right column. It matters where the column is dropped or not. Write again if you need further assistance.

All the best,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
jv
Top achievements
Rank 1
answered on 04 Jan 2010, 09:35 AM
Hello,

I had exactly the same problem with RadGridView with the latest version.
With no DataSource defined I could reorder columns, but when the radgridview had a DataSource, i couldn't reorder columns anymore, I mean I tried to reodre columns, no changes were visible but when I changed the datasource again (in the click event of a button for example) the columns order was changed.
I finally found the solution, it was because I set the ReadOnly property of MasterGridViewTemplate to True, so I set this property to False and disable editing rows for the users instead... I hope It helps.
0
Victor
Telerik team
answered on 04 Jan 2010, 10:28 AM
Hello jv,

Thank you for your post, the provided information will be helpful to our community. Please write again if you have more questions about our controls.

Regards,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Zsolt Hunyadi
Top achievements
Rank 1
answered on 18 Mar 2010, 04:13 AM
Hello,

I had exactly the same problem with RadGridView, but I found a fast solution:

Try to reorder from RadGridView Tasks Columns (Collection), not from Opening Property Builder.
Tags
GridView
Asked by
Glen Luettgrodt
Top achievements
Rank 1
Answers by
Victor
Telerik team
Glen Luettgrodt
Top achievements
Rank 1
jv
Top achievements
Rank 1
Zsolt Hunyadi
Top achievements
Rank 1
Share this question
or