I have a Time column that is string formatted in "HH:mm:ss" format.The sort on this is set to descening , some times the sort is not correct as it is a string.
I already have a hidden column that has values in ticks.So when ever the user tries to sort on time column, i thought i would apply the sort order on this
hidden column. How do i acheive this??
I dont want to use the sort comparer as it is taking some cpu.
While going through some other posts i saw that setting the headerclickaction to external will help , but i only want to perform my sorting on
the hidden column only when the user clicks on the Time Column.
Thanks in advance,
Vj
Okay... it sounds to me like what you want to do is set the HeaderClickAction on the Time column to SortSingleExternal or SortMultiExternal. This makes it so that the header wil show a sort indicator and react when the user clicks on it, but not actually sort anything. Then you can handle Before or AfterSortChange, like you are doing here, and just copy the SortIndicator property from the Time column to the Ticks column.
Hi Mike,
Thanks for the quick response.I have already tried this and it works but like i mentioned in my post earlier it is quite cpu intensive as the data frequency in our applicaiton is quite high and whenever a new row is added casting to ultragridcell i feel is quite expensive operation.we had some cpu statistics with the icompare implementation vs with out any . The ICompare implementation consumes quite a bit of cpu with the frequency of data in our application.
What i was looking for is a solution where i apply sorting on another hidden column called DayTime which is a long value when the user clicks on the Time Column
To acheive this iam trying to apply the sortindicator of the Time Column on the DayTime column.
void UnderlyingGrid_AfterSortChange(object sender, BandEventArgs e)
{
SortedColumnsCollection sortedColl = this.dataGrid.UnderlyingGrid.DisplayLayout.Bands[0].SortedColumns;
if (sortedColl.Count > 0)
for (int i = 0; i<=sortedColl.Count-1; i++)
if (sortedColl[i].Key == "Time")
if (e.Band.Columns["DayTime"].SortIndicator != e.Band.Columns["Time"].SortIndicator)
e.Band.Columns[
"DayTime"].SortIndicator = e.Band.Columns["Time"].SortIndicator;
}
break;
Now the issue is i have to disable sorting on the header click of the time column.
Hi Vj,
You can do this using the SortComparer property on the Column. What you do is create a class that implement IComparer. The IComparer interface is very simple, it only has one method: Compare.
The Compare method passes you two objects: X and Y. In the case of the grid, these objects will be of type UltraGridCell. So you cast them into UltraGridCells. From there, you can get the Row and from there you can get hidden cells that contain the ticks.
Then all you have to do is something like this:
return ticksX.CompareTo(ticksY);