datetime - Sorting a string column on time field is not working in ultrawingrid in vb.net -
i developing desktop application , using infragistic controls version 12.1. in ultrawingrid there columns id,time,name, description etc.
id time name description 1 10.45 - 11:15 abc abc 2 09:15 - 09.45 xyz xyz 3 02:00 pm - 02.15 pm abdd abdd 4 03:00 pm - 03.45 pm efg efg 5 01:15 pm - 01:45 pm bcd efg
now if click on header of column except time column , try sort works fine. when click on header of time column not working. should returns following way.
id time name description 2 09:15 - 09.45 xyz xyz 1 10.45 - 11:15 abc abc 5 01:15 pm - 01:45 pm bcd efg 3 02:00 pm - 02.15 pm abdd abdd 4 03:00 pm - 03.45 pm efg efg
but how not return correctly. , time column string field. sorting according string type field. want sort time column time field. not working.
so can suggest me how this?
thanks in advance,
the mentioned behavior expected, because [time] column has data type of string. maybe 1 possible approach solve task, if using icomparer interface. way implement custom sorting behavior.
i have similar sample used icomparer interface. there should sort integer absolute values. use sample starting point. more details icomparer interface find at: http://help.infragistics.com/help/netadvantage/winforms/2013.1/clr4.0/html/infragistics4.win.misc.v13.1~infragistics.win.misc.navigationbarlocationscollection~sort(icomparer).html
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.windows.forms; using system.collections; using infragistics.win.ultrawingrid; namespace ultragridsortbyabsvalue { public partial class form1 : form { public form1() { initializecomponent(); datatable dt = new datatable(); dt.columns.add("a", typeof(string)); dt.columns.add("b", typeof(double)); dt.columns.add("c", typeof(double)); dt.rows.add("test 1", 10, 23.3); dt.rows.add("test 2", 30, 23.4); dt.rows.add("test 3", -20, 21.3); dt.rows.add("test 4", -40, 12.3); dt.rows.add("test 5", -50, -22.7); dt.rows.add("test 6", 60, 22.3); dt.rows.add("test 7", -70, 26.8); dt.rows.add("test 8", 80, 13.3); dt.rows.add("test 9", 90, 29.1); ultragrid1.datasource = dt; ultragrid1.displaylayout.bands[0].columns["c"].style = infragistics.win.ultrawingrid.columnstyle.currency; ultragrid1.displaylayout.bands[0].columns["c"].format = "$ #,##0.00;$ -#,##0.00; $ -"; ultragrid1.displaylayout.bands[0].columns["c"].cellappearance.texthalign = infragistics.win.halign.right; } private void ultragrid1_aftersortchange(object sender, bandeventargs e) { ultragrid1.displaylayout.bands[0].columns["b"].sortcomparer = new sortcomparer(); } private void ultragrid1_initializegroupbyrow(object sender, initializegroupbyroweventargs e) { //e.row.column.sortcomparer = new sortcomparer(); } } public class sortcomparer : icomparer { // custom sorting - sort abs values int icomparer.compare(object x, object y) { ultragridcell cell1 = x ultragridcell; ultragridcell cell2 = y ultragridcell; string string1 = math.abs((double)cell1.value).tostring(); string string2 = math.abs((double)cell2.value).tostring(); int ret; if (string1 == null) { ret = -1; } else if (string2 == null) { ret = 1; } else { ret = string.compare(string1, string2, true, system.globalization.cultureinfo.currentculture); } return ret; } } }
Comments
Post a Comment