المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : DataGrid date sorting [modified]



C# Programming
11-27-2009, 09:30 AM
I´m developing a Windows Forms app with C# 2003. Well, I´ve got a DataGrid control with 2 Date columns with "dd/MM/yyyy" format...the trouble is that when I click that columns' headers they get obviously sorted by day, then month, and then year (01-02...30,31)...and I want them to get sorted by year, then month and then day...I´ve placed this code on the datagrid_mouseup event...so when the datagrid sorts the column it will do it correctly...but I don´t know how to revert back the date format, because the sorting method seems to be internal and performed after all other DataGrid´s events are processed. So how could I know when DataGrid has finished sorting to put the dates into their former format? (or other way of doing it, of course). Thanx.


DataGrid.HitTestInfo hitTestInfo = myDataGrid2.HitTest(myDataGrid2.PointToClient(Control.MousePosition));

if (hitTestInfo.Type==DataGrid.HitTestType.ColumnHeader)
{
if ((hitTestInfo.Column==2)||(hitTestInfo.Column==3))
{
for (int i=0;i