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.
Unfortunately, activation email could not send to your email. Please try again.

GridListControl sort column and column width

Thread ID:

Created:

Updated:

Platform:

Replies:

60190 Apr 30,2007 08:42 AM Apr 20,2017 10:16 AM Windows Forms 11
loading
Tags: GridControl
Dan Garvin
Asked On April 30, 2007 08:42 AM

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.

haneefm [Syncfusion]
Replied On April 30, 2007 01:31 PM

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

Zheng Lin
Replied On June 19, 2007 06:08 PM


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

haneefm [Syncfusion]
Replied On June 19, 2007 07:06 PM

Hi Zheng,

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

Best regards,
Haneef

Zheng Lin
Replied On June 20, 2007 01:53 PM

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

haneefm [Syncfusion]
Replied On June 20, 2007 02:05 PM

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

Zheng Lin
Replied On June 21, 2007 01:32 PM

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

haneefm [Syncfusion]
Replied On June 21, 2007 07:00 PM

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

Zheng Lin
Replied On June 22, 2007 10:35 AM

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

haneefm [Syncfusion]
Replied On June 25, 2007 06:54 PM

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

Vincent Duvernet
Replied On April 19, 2017 06:01 PM

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;

Mohanraj Gunasekaran [Syncfusion]
Replied On April 20, 2017 10:16 AM

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 


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.

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.

;