sorting - sort columns with different type in data grid view -
i have data grid view columns : identitynumber , name , date . each column represents different types of values . identitynumner integer , name string , , date datetime.
my goal click on column's header , sort done accoding types above. auto sort without doing sort string can see . how achive goal ?
i have found solution problem . please check answer below .
found solution problem :
inside ctor of form registered data grid view's sortcompare event :
datagridview1.sortcompare += new datagridviewsortcompareeventhandler(mycustomsortfunction);
the custom function iv'e build :
void mycustomsortfunction(object sender, datagridviewsortcompareeventargs e) { try { // checks if column's header pressed identity number - // if , sort integer . if (e.column.name == "colidentity") { int = convert.toint32(e.cellvalue1.tostring()); int b = convert.toint32(e.cellvalue2.tostring()); e.sortresult = a.compareto(b); e.handled = true; } // checks if column's header pressed date - // if , sort datetime . else if (e.column.name == "colhdate") { datetime c = convert.todatetime(e.cellvalue1.tostring()); datetime d = convert.todatetime(e.cellvalue2.tostring()); e.sortresult = c.compareto(d); e.handled = true; } } catch { } }
hope answer :-) shuki .
Comments
Post a Comment