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

Show columns in specific order by default

1 Answer 98 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 2
Patrick asked on 05 Jun 2013, 04:30 PM
I'm trying to figure out the easiest way to have my columns start in a default order(left to right) for all users.  I tried setting them in the IList<T> that I use to populate the DataSource but that doesn't work.  

Do I have any options besides setting each column manually following the instructions on this page -->Reordering Columns

That would be VERY cumbersome...


Additionally, I notice that Intellisense labels
RadGridView1.Columns.Move();
as "[deprecated]" so what is the alternative?


RadGridView1.Columns.Move()
RadGridView1.Columns.Move()

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 10 Jun 2013, 06:22 AM
Hi Patrick,

Thank you for writing.

The grid will read your objects fields in the way they are defined and based on this way will produce its columns. For example:
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
 
        List<MyObject> l = new List<MyObject>();
        l.Add(new MyObject() { FirstColumn = 1, SecondColumn = "2" });
        radGridView1.DataSource = l;
    }
}
 
class MyObject
{
    public string SecondColumn { get; set; }
    public int FirstColumn { get; set; }
 
}

this would produce a grid where the SecondColumn will be first and the FirstColumn will be second, while using the following object will do the opposite:
class MyObject
{
    public int FirstColumn { get; set; }
    public string SecondColumn { get; set; }
}

As to the obsolete Move method, there is another Move method with different signature that should be used instead:
[Obsolete("This method is obsolete and will be removed for the next release. Please use Move(int oldIndex, int newIndex) instead.")]

I hope this helps.
 
Regards,
Stefan
Telerik
RadChart for WinForms is obsolete. Now what?
Tags
GridView
Asked by
Patrick
Top achievements
Rank 2
Answers by
Stefan
Telerik team
Share this question
or