Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
290
Sorting issue with SetDataBinding() using List<object>
posted

Hello,

My problem deals with trying to get dates to sort chronologically by clicking on a column header. I feel it has to do with how the data is bound to the grid as other grids in this project do not have this same problem. The other grids only have one list of class objects being bound to them. The grid with the problem has two classes being added to a list of objects, List<object>, and then binding the object list to the grid. Here's some psuedo code and actual code of what I am doing.

 

I set up the grid like this:

                this.DisplayLayout.Bands[0].Columns.Add("DateMod", "Date");
                this.DisplayLayout.Bands[0].Columns["DateMod"].Format = WindentConstant.SHORTDATEFORMAT;
                this.DisplayLayout.Bands[0].Columns["DateMod"].CellDisplayStyle = Infragistics.Win.UltraWinGrid.CellDisplayStyle.FormattedText;
                this.DisplayLayout.Bands[0].Columns["DateMod"].DataType = typeof(DateTime);

 

I bind the data to the grid like this:

List<DocumentData> myDocumentData;    (assume this is already bound from a db)

List<NoteData> myNoteData;     (assume this is already bound from a db)

List<object> mySourceObjects = new;

foreach (DocumentData in myDocumentData)

mySourceObjects.Add(DocumentData);

foreach (NoteData in myNoteData)

mySourceObjects.Add(NoteData);

SetDataBinding(mySourceObjects, null, true);

 

In the InitializeRow method:

if (e.Row.ListObject.GetType() == typeof(DocumentData))

e.Row.Cells["DateMod"].Value = ((DocumentData)e.Row.ListObject).DateCreate;

else

e.Row.Cells["DateMod"].Value = ((NotesData)e.Row.ListObject).DateCreate;

(DateCreate, for both objects, is a DateTime property.)

 

 

So the values show up properly in the grid, but the sort on the DateMod column will not sort the values in chronological order. I wish to fix this sort problem without implementing another class to combine the DocumentData and NoteData classes. Am I missing some properties that need to be set in the grid? Thanks in advance.