We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How do you group and sort when the form of the object is unknown until runtime?

- Or how do you group and array of objects?

I have a situation where I need to group and sort data that can change form during runtime. I basically have an ArrayList of ArrayLists. That data takes the form of the outer ArrayList being the rows, and an inner ArrayList being the columns. For example the data will look like this:

m_data = new ArrayList(8);
MyList inner;

inner = new MyList(3);
inner.Add(new SampleData("Ray"));
inner.Add(new SampleData("Red"));
inner.Add(new SampleData("42"));
m_data.Add(inner);

inner = new MyList(3);
inner.Add(new SampleData("Joe"));
inner.Add(new SampleData("Black"));
inner.Add(new SampleData("66"));
m_data.Add(inner);


The number of columns can change, but they will always be made up of the same object. The columns that are grouped and sorted will change.

I took the approach of using a custom Categorizer, and this works fine if I only group on one column, but not on two or more. I suspect that I will need my own Comparer, but I don’t have enough context to know what values I need to compare. It seems that the SortColumnDescriptor name is used as the property name for the object. How can I use a different name for the SortColumnDescriptor that is used to obtain the property value that is used for the sort?

I have enclosed a simplified version of the code that demonstrates things better then I can explain then in text.

Ken




SuperSimple.zip

2 Replies

KV Kenneth Vrana August 2, 2006 03:18 PM UTC

The sample code has an error in SetupGrouping() where the first line in the method where "Val" is bing added as a GroupedColumns should be removed. This is why one of the groups worked, where now none of them do.


AD Administrator Syncfusion Team August 9, 2006 01:14 PM UTC

Hi Ken,

Sorry for delayed reply. In the main list (m_data), the only public property is Me. So, that is the only thing the engine can see, and the only thing that can be sorted easily. So, one way to manage this is to have the MyList class implement IComparable. This will allow you to control how the Me property gets sorted. If you want to sort it on several of the objects in the actual child list, then you can make the IComparable implemetation do this. Attached is a modified sample to do a multiple column sort. But since the engine is not exposed to any other property(column) directly, its not possible to add columns in the GroupedColumns collection. Let us know if you need any further assistance.

Regards,
Calvin.

Forum47311.zip

Loader.
Live Chat Icon For mobile
Up arrow icon