We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

change column order in GridList control

The GridGrouping control has the TableDescriptor property that allows for changing the order of displayed columns.
How can we change the column display order for the GridList control ?

3 Replies

HA haneefm Syncfusion Team October 2, 2007 05:38 PM UTC

Hi Omar,

First Technique:

You can subclass GridListControl and override the CreateGridColumn member. A column is passed into this member as a parameter. Before calling the baseclass, modify this column in such a manner as to create the columns in the order you want to see them. So, for example, if you want to swap columns 1 & 2, then code such as this should do it.

public class MyGridListControl : GridListControl
{
public override void CreateGridColumn(PropertyDescriptor pd, int column)
{
if(column == 1)
column = 2;
else if(column == 2)
column = 1;

base.CreateGridColumn(pd, column);
}
}

Second Technique:
>>>>>>>>>>>>>>>>>>>>>>>>>

You can do this by handling the PrepareViewStyleInfo event of the Grid and set the cellValue using the Hashtable. This Hashtable store the column information of the gris. You can handle the events either at the form level, or the control level.Here is code snippet,

//Form''''s Load event
this gridListcontrol.Grid.PrepareViewStyleInfo += new GridPrepareViewStyleInfoEventHandler(Grid_PrepareViewStyleInfo);

void Grid_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
{
GridControl grid = sender as GridControl;
if (hash.Contains(e.ColIndex))
{
if (hash[e.ColIndex] != null)
{
e.Style.CellValueType = grid[e.RowIndex, int.Parse(hash[e.ColIndex].ToString())].CellValueType;
e.Style.Text = grid[e.RowIndex, int.Parse(hash[e.ColIndex].ToString())].Text;
}
}

}

Here is a sample for implementing it.
http://www.syncfusion.com/Support/user/uploads/reorder_7dbe1840.zip

Best regards,
Haneef


KJ Kjetil October 23, 2007 03:14 PM UTC

Hello,

I had the same issue, trying to control the column order in a GridListControl.

I tried creating a new control that inherits from GridListControl and overriding the CreateGridColumn method. But it still doesn't work. To me it looks like it's the order the CreateGridColumn is called in that matters.

Any tips here?
Thanks,
Kjetil


HA haneefm Syncfusion Team November 2, 2007 07:30 PM UTC

Hi Kjetil,

One way you can do this by using the PropertyDescriptorCollection in a CreateGridColumn method. Here is the code snippet that shows this task.

public class MyGridListcontrol : GridListControl
{
public MyGridListcontrol()
: base()
{
}
public override void CreateGridColumn(PropertyDescriptor pd, int column)
{
CurrencyManager cm = this.BindingContext[this.DataSource] as CurrencyManager;
PropertyDescriptorCollection pdc = cm.GetItemProperties();
if (pdc != null)
{
if (column == 1)
column = 2;
else if (column == 2)
column = 1;
base.CreateGridColumn(pdc[column - 1], column);
}
}
}

Here is a sample for your reference.
GridListColumnReorder.zip

Best regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon