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.

Want Sort icon in Column Header

Thread ID:

Created:

Updated:

Platform:

Replies:

66599 Jul 31,2007 09:32 AM Aug 1,2007 02:10 PM Windows Forms 3
loading
Tags: GridControl
Gourav Nayyar
Asked On July 31, 2007 09:32 AM

hi
i have a griddatabound Grid in which i have a column as "expiry date" and the datain it is of string type , so when we sort it , it does'nt sort according to datetime b'cas its string. so for that i have write my own code on CellClick is that if colindex is that one then sort the datatable and bind it to grid. thats solve my problem , but the issue is that i also want sort icon when user click on the column , so please suggest me solution according to thsi Grid (gridDataBound Grid) . and one more thing is that when i set the datasource of sorted datatable to grid , that time the scroll bar of the grid again moves to start point , that's i not want .
so please look in this issuee and solve my problem.

i'll also attached the code with it

Thanks
Gourav

gridsort.zip

haneefm [Syncfusion]
Replied On July 31, 2007 11:44 AM

Hi Gourav,

The GridDataBoundGrid really does not do any sorting. It delegates the sorting to the IBindingList datasource. So, if you are using a DataTable as the grid''s datasource, it is the dataTable.DefaultView that is doing the sorting. So, if you are seeing the dates being sorted like strings, it suggests that the type of this DataColumn in the DataTable is a string object and not a DateTime object. If this is the case, the simplest way to handle the problem would be to store the value as a DataTime and set GridBoundColumn.StyleInfo.Format to tell the grid to display the DateTime value with a particular format.

If this is not possible, then you would have to do some work to work around the string type being set in the datasource. Here is a forum thread that discusses a couple of ways to do this and has sample information. But changing the DataColumn type will be the simplest solution.

http://www.syncfusion.com/support/forums/message.aspx?&MessageID=21940

Best regards,
Haneef

Gourav Nayyar
Replied On August 1, 2007 02:18 AM

Hi Haneef
Thanks for solution , but my problem is not that you understand. my problem is " i have done sorting manually in my grid by my own code , but now i want to show sort icon on the grid when i click on grid "
so pl'z send me code regarding that.

Thanks
Gourav

>Hi Gourav,

The GridDataBoundGrid really does not do any sorting. It delegates the sorting to the IBindingList datasource. So, if you are using a DataTable as the grid's datasource, it is the dataTable.DefaultView that is doing the sorting. So, if you are seeing the dates being sorted like strings, it suggests that the type of this DataColumn in the DataTable is a string object and not a DateTime object. If this is the case, the simplest way to handle the problem would be to store the value as a DataTime and set GridBoundColumn.StyleInfo.Format to tell the grid to display the DateTime value with a particular format.

If this is not possible, then you would have to do some work to work around the string type being set in the datasource. Here is a forum thread that discusses a couple of ways to do this and has sample information. But changing the DataColumn type will be the simplest solution.

http://www.syncfusion.com/support/forums/message.aspx?&MessageID=21940

Best regards,
Haneef

haneefm [Syncfusion]
Replied On August 1, 2007 02:10 PM

Hi Gourav,

You can handle the QueryCellInfo event of the grid and set the e.Style.Tag property of the column header to your sort direction. Below is a code snippet

void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
if (e.ColIndex == 7 && e.RowIndex == 0)
{
e.Style.Tag = sortDirection;
// for ascending ListSortDirection.Ascending;
// e.Style.Tag = ListSortDirection.Ascending;
}
}


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.

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.

;