I have a GDBG where one of the columns has a custom dropdown that allows the user to specify a start date & time, an end date and time and an indication as to whether the times are estimates or not. Basically this dropdown populates four columns in a table. The cell in the grid displays the results as a string that looks like this (example) :
02/01/2004 14:00:00 - 04/04/2004 15:00:00
When a sort is done, it is basically a string sort so ... 02/01/2004 appears before 03/02/2003 as an example. How can I trap a sort for this particular column so that I can sort on the actual database columns that are of type datetime?
ADAdministrator Syncfusion Team November 29, 2004 05:05 PM
The GridDataBoundGrid uses the sorting support from the DataView associated with the DataSource. To do a custom sort through the DataView, the object in the column should implement IComparable. When this is done, the DataView will use the IComparable implementation when it tries to sort that column. Here is a forum thread with a sample. http://188.8.131.52/Support/Forums/message.aspx?MessageID=18035
Here is another way to do this that is more involved than just implementing IComparable on a derived object, but it does allow you to sort things with out deriving an object. It does away with teh grid depending upon the DataView.Sort support. This way you can sort columns and not see them move around as you edit entries. You only have to have an IComparer that you can use. You can also use this technique to sort unbound columns.
LOLoriJanuary 6, 2005 03:26 PM
Thanks Clay, I''ll take a look at that sample you provided.
One more question - what I''d like to do is, for one column in the grid, sort by a different column that is in the same DataTable that is the DataSource of the grid. Is there an event that I can trap and do this? I know that CellDoubleClicked occurs before the Sort is set.
ADAdministrator Syncfusion Team January 6, 2005 03:31 PM
Check out this sample. It shows how you can intercept a sort and sort somethiing else.