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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

change column order in GridList control

Thread ID:

Created:

Updated:

Platform:

Replies:

68813 Oct 2,2007 11:20 AM UTC Nov 2,2007 07:30 PM UTC WinForms 3
loading
Tags: GridControl
Omar Shraim
Asked On October 2, 2007 11:20 AM UTC

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 ?

haneefm [Syncfusion]
Replied On 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

Kjetil
Replied On 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

haneefm [Syncfusion]
Replied On 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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;