Hi,
I am facing a problem while sorting on date column when header is clicked. The dates are sorted as string.
The following is the code i am using.
sprData.SetText(SPR_COL_DTM, idx,
).value))
this is the code which populates the column in Ultrawingrid.
Thank you,
Basavaraj P Hiremath.
If column not have data type like DateTime, the data will be sorting like string.
How to change the data type of the column? when i try to change the property of the Ultrawin grid, its not allowing? is there any way so that i can change the property of the column at run time by coding ?
You can't change the data type of bound columns because that is dictated by the underlying DataColumn (assuming you are bound to a DataTable). The DataColumn class exposes a DataType property which is settable, but if the data is coming from a database then the data itself is of type string, which limits your options.
The value that is coming from database is of "date" data type. Do i need to convert this to integer type then sort it and then again convert it back to date and then populate the grid...?
It would be better to use SortComparer that simply ignores the time portion of the date than to alter the data in this way or return a date as a string.
Ths is happening due to the Date + Time format is bound to the coloumn. To acheive both sorting and filtering sametime you need to get the date portion out before bind it to the grid. I had the same problem and I could achive it using following code in the SQL select statement.
CONVERT(datetime, CONVERT(CHAR(10), OrderDate, 103), 103) as OrderDate
If the values in the column are of type DateTime, then they will be sorted as dates. There is no Date datatype in DotNet as far as I am aware.
It sounds to me like your database is using some unusual type that the DotNet BindingManager or DataTable does not know how to handle and so it's falling back to using strings. That has nothing to do with the grid and the grid has no control over this.
If you need to handle the sorting yourself, you could use a SortComparer on the grid column and compare the values yourself. Perhaps you can use DateTime.Parse to convert the date strings into actual dates.
But you might be better off trying to find out why your date values are being interpreted by DotNet as string, since sorting will not be the only problem this causes. You will have problems filtering, summarizing, and dealing with the dates in a whole lot of ways if they are stored as strings.