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

GridListControl sort column and column width

How do you sort a column in a GridListControl. I'm dropping down a grid (multi-column drop down) from a cell and I'd like to allow the user to click on the column header to sort a column, like they would in a normal databound grid. Is this possible?

I would also like to countrol the column width of the drop down grid columns. Is this possible? Thanks.

11 Replies

HA haneefm Syncfusion Team April 30, 2007 05:31 PM UTC

Hi Dan,

How do you sort a column in a GridListControl?
>>>>>
1) There is no support for soring in the GriListControl. Any sorting you do will have to be done on the DataSource. Now you can try to subscribe to the CellClick event in the embedded GridControl, and do the sorting at that point, but it will take some coding. You could use the techniques shown in \Grid\Samples\Quick Start\GridControlSort catch the event and try to do your own sorting in your DataSource. But to handle showiing the Sort icon, you would have to subscribe to the QueryCellInfo event of the mebedded grid to dynamically set the sort icon cell control.

countrol the column width of the drop down grid columns
>>>>
2)Here is a KB article that shows you "How to set the properties of the embedded grid in the GridListControl CellType?".
http://www.syncfusion.com/Support/article.aspx?id=10353

Best regards,
Haneef


ZL Zheng Lin June 19, 2007 10:08 PM UTC


Hi,
This is exactly what I am trying to accomplish too. But I could not find the quickstart sample referenced. Could you tell me where exactly it is available, or could you give me a downloadable version?

Thanks greatly.

zheng
>Hi Dan,

How do you sort a column in a GridListControl?
>>>>>
1) There is no support for soring in the GriListControl. Any sorting you do will have to be done on the DataSource. Now you can try to subscribe to the CellClick event in the embedded GridControl, and do the sorting at that point, but it will take some coding. You could use the techniques shown in \Grid\Samples\Quick Start\GridControlSort catch the event and try to do your own sorting in your DataSource. But to handle showiing the Sort icon, you would have to subscribe to the QueryCellInfo event of the mebedded grid to dynamically set the sort icon cell control.

countrol the column width of the drop down grid columns
>>>>
2)Here is a KB article that shows you "How to set the properties of the embedded grid in the GridListControl CellType?".
http://www.syncfusion.com/Support/article.aspx?id=10353

Best regards,
Haneef


HA haneefm Syncfusion Team June 19, 2007 11:06 PM UTC

Hi Zheng,

Please refer this sample and let me know if this helps.
GridControlSort.zip

Best regards,
Haneef


ZL Zheng Lin June 20, 2007 05:53 PM UTC

The sample looks great, seems exactly what I need.
However, when I apply the same code to my application, nothing happens. Debugging shows that the cell click event handler never gets called.
The difference of our use case is that I am trying to add sorting capability to a gridlistcontrol which is part of a comboboxext, any idea what I am missing here?

Thanks greatly!

zheng

>Hi Zheng,

Please refer this sample and let me know if this helps.
GridControlSort.zip

Best regards,
Haneef


HA haneefm Syncfusion Team June 20, 2007 06:05 PM UTC

Hi Zheng,

Here is a forum thread that discuss with grid listcontrol sort technique. It also implements a multi sort feature if you hold down the Control key.
http://www.syncfusion.com/support/Forums/message.aspx?&MessageID=21917

Best regards,
Haneef


ZL Zheng Lin June 21, 2007 05:32 PM UTC

Hi, Haneef,
All your responses have been right on the money, thank you very much!
Now I have a follow on question in the same project. Following the sample, I am able to sort the columns of the embedded grid in a comboboxext. However, the sorting behavior is not what I desired for one of the columns --- it is a string column but mainly store integer numbers. The sorting makes it go as "10,100,20" rather than (10,20,100). I was hoping I can squeeze in a custom comparer somewhere, but could not find a good entrance for the DataView or DataTable object that is currently used for the sorting.
I did notice however, this is possible with the GridData object. But the GridlistControl.Grid.Data object seems to be null at runtime. Why is that? Is there anyway to bind it with the GridListControl.DataSource or use it somehow for the custom sorting purpose?

Thanks.

zheng

>Hi Zheng,

Here is a forum thread that discuss with grid listcontrol sort technique. It also implements a multi sort feature if you hold down the Control key.
http://www.syncfusion.com/support/Forums/message.aspx?&MessageID=21917

Best regards,
Haneef


HA haneefm Syncfusion Team June 21, 2007 11:00 PM UTC

Hi Zheng,

You need to create a class that implements IComparable interface and overrides CompareTo() method from that class to change the sorting behavior. And then you can add a column of that type to your datatable. When you sort a dataview based on that datatable by the column, It will use your IComparer class. Below is a code snippet

Public class CustomType : IComparable
{
public CustomType(string s)
{
Value = s;
}

int IComparable.CompareTo(object obj)
{
int iv1 = System.Convert.ToInt32( this.Value);
int iv2 = System.Convert.ToInt32( (CustomType)obj).Value));
return iv1.CompareTo( iv2);
}

private string _Value;
public string Value { set { _Value = value; } get { return _Value; } }

public override string ToString()
{
return _Value;
}
}

DataTable dt = new DataTable();
dt.Columns.Add("Column1");
dt.Columns.Add("Column2", typeof(CustomType));

dt.Rows.Add(new object[] {"a", new CustomType("111") });

dt.AcceptChanges();

Here is a forum thread that discuss with the GridData.SortByColumnMethod.
http://www.syncfusion.com/support/forums/message.aspx?&MessageID=7562

Best regards,
Haneef


ZL Zheng Lin June 22, 2007 02:35 PM UTC

Again great information. :)
I did as you said, now the hurdle is, the compare method isnt getting called even though I did change the style.cellvaluetype = NumericSortString(my custom type).
I did the change in the querycellinfo event handler:
if( e.Style.CellValueType == typeof(System.String))
e.Style.CellValueType = typeof(NumericSortString);

e here is the GridQueryCellInfoEventArgs and when I debug through it, this step does get called for every cell on the grid.

Anything I missed here?

Thanks.

zheng

>Hi Zheng,

You need to create a class that implements IComparable interface and overrides CompareTo() method from that class to change the sorting behavior. And then you can add a column of that type to your datatable. When you sort a dataview based on that datatable by the column, It will use your IComparer class. Below is a code snippet

Public class CustomType : IComparable
{
public CustomType(string s)
{
Value = s;
}

int IComparable.CompareTo(object obj)
{
int iv1 = System.Convert.ToInt32( this.Value);
int iv2 = System.Convert.ToInt32( (CustomType)obj).Value));
return iv1.CompareTo( iv2);
}

private string _Value;
public string Value { set { _Value = value; } get { return _Value; } }

public override string ToString()
{
return _Value;
}
}

DataTable dt = new DataTable();
dt.Columns.Add("Column1");
dt.Columns.Add("Column2", typeof(CustomType));

dt.Rows.Add(new object[] {"a", new CustomType("111") });

dt.AcceptChanges();

Here is a forum thread that discuss with the GridData.SortByColumnMethod.
http://www.syncfusion.com/support/forums/message.aspx?&MessageID=7562

Best regards,
Haneef


HA haneefm Syncfusion Team June 25, 2007 10:54 PM UTC

Hi Zheng,

Thank you for your update.

I am not sure of what be might be causing this strange behavior without a working sample. Is it possible for you to upload us a minimal sample to reproduce the issue here? This will help us to analyse the issue further.

Best regards,
Haneef


VD Vincent Duvernet April 19, 2017 10:01 PM UTC

This is an old topic but I had the same problem tonight.

Because my GridListControl is linked to a database throw DataSource member with EntityFramework, I must keep the auto-generated POCO classes so I can't implement IComparable.

Here is what I do :

public partial class Country {
        public virtual int Id
        {
            get;
            set;
        }

        public virtual string Name
        {
            get;
            set;
        }
}
[...]

List<Country> countries = db.Countries.ToList();
countries = countries.OrderBy(w => w.Name).ToList();
myGridListControl.DataSource = countries;


MG Mohanraj Gunasekaran Syncfusion Team April 20, 2017 02:16 PM UTC

Hi Dan, 

Thanks for your update. 

By default, GridListControl do not have the support to sort the column. But you were right, you can also sort the list values using LINQ query before that assigning the datasource for GridListControl

Regards, 
Mohanraj G 


Loader.
Live Chat Icon For mobile
Up arrow icon