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

GridGroupingControl & CustomCategorizer

Hi, I''m trying to build a GridGroupingControl with a custom catgorizer. The categorizer read the ''n'' first characters of a string to obtain the category key. I want to obtain this result : + 1* Name Phone + 11* Name Phone 110 Bob 4567 111 Sim 7654 + 12* etc. An exception is raised when i try to add the second group criteria (on the same column). Une exception non gérée du type ''System.Exception'' s''est produite dans syncfusion.grouping.base.dll Informations supplémentaires : Column ''Numero'': Duplicates are not allowed I have created a simple C# example for more details (look at InitializeGroupColumns method). It doesnt look like your uploads are working again so i will email this to you at support@syncfusion.com. Any advices are welcome to obtain this behavior. Regards Mikaël

3 Replies

AD Administrator Syncfusion Team March 17, 2005 10:13 AM UTC

Thanks for the sample. I have 2 suggestions as to how to handle this problem. The first suggestion is more to show what needs to be done, but is a little extravagant with respect to memory resources so you might not want to use it. The second one is probably what you want to use. Important aspects of a SortColumnDescriptor are the Categorizer and the Comparer. You are already trying to use the categorizer, but I think you will ultimately want to also use a custom comperer as this is how you can effectively group by the same column several times. The first suggestion is to add Expression fields, one for each additional grouping you want, and then to group by these added invisible columns. Here is code that did that for me in your sample. private void InitializeGroupColumns() { //group "Col2" using a custom categorizer and Comparer Syncfusion.Grouping.SortColumnDescriptor cd = new SortColumnDescriptor("Numero"); cd.Categorizer = new CustomCategorizer(1); this.gridGroupingControl1.TableDescriptor.GroupedColumns.Add(cd); ExpressionFieldDescriptor efd = new ExpressionFieldDescriptor("NumeroXX", "[Numero]"); this.gridGroupingControl1.TableDescriptor.ExpressionFields.Add(efd); cd = new Syncfusion.Grouping.SortColumnDescriptor("NumeroXX"); cd.Categorizer = new CustomCategorizer(2); this.gridGroupingControl1.TableDescriptor.GroupedColumns.Add(cd); efd = new ExpressionFieldDescriptor("NumeroXXX", "[Numero]"); this.gridGroupingControl1.TableDescriptor.ExpressionFields.Add(efd); cd = new Syncfusion.Grouping.SortColumnDescriptor("NumeroXXX"); cd.Categorizer = new CustomCategorizer(3); this.gridGroupingControl1.TableDescriptor.GroupedColumns.Add(cd); } A better solution is based on the idea that SortColumnDescriptors do not necessarily have to be accoicated with a particular column IF you define a CustomComparer for the SortColumnDescriptor that can accept the records being compared, and return teh value you want. So, instead of adding 3 SortColumndescriptors (as above) tied to columns in the data and using the associated default comparer object, just add 3 SortColumnDescriptors with three CustomComparers that just compares the fixed Numero column. It is in this manner that you can use the same column 3 times (or more) with grouping. private void InitializeGroupColumns() { this.gridGroupingControl1.TopLevelGroupOptions.CaptionText = "{Category}x-{RecordCount}"; this.gridGroupingControl1.ChildGroupOptions.CaptionText = "{Category}x-{RecordCount}"; //group "Col2" using a custom categorizer and Comparer Syncfusion.Grouping.SortColumnDescriptor cd = new SortColumnDescriptor(); cd.Name = "1"; cd.Comparer = new CustomComparer("Numero"); cd.Categorizer = new CustomCategorizer(1, "Numero"); this.gridGroupingControl1.TableDescriptor.GroupedColumns.Add(cd); cd = new SortColumnDescriptor(); cd.Name = "2"; cd.Comparer = new CustomComparer("Numero"); cd.Categorizer = new CustomCategorizer(2, "Numero"); this.gridGroupingControl1.TableDescriptor.GroupedColumns.Add(cd); cd = new SortColumnDescriptor(); cd.Name = "3"; cd.Comparer = new CustomComparer("Numero"); cd.Categorizer = new CustomCategorizer(3, "Numero"); this.gridGroupingControl1.TableDescriptor.GroupedColumns.Add(cd); } Here is your sample back modified in this manner. http://www.syncfusion.com/Support/user/uploads/GGC_CustomCategorizer_Forum_9692f143.zip


MM Mikaël Morvan March 17, 2005 11:31 AM UTC

Thanks for your suggestions. It is exactly what i want. I tryied the 2 methods but the result is not exactly the same. The order in the first suggestion is : + 1* + 10* + 12* + 14* + 16* The order in the second suggestion is : + 1* + 14* + 16* + 10* + 12* Why the order is different ? Is it due to the comparer ? How to obtain the first result with the second method ? Mikaël


AD Administrator Syncfusion Team March 17, 2005 01:06 PM UTC

Turns out that it is simpler than I thought. You do not need the custom comparer at all. You can get the column properly sorted using the very first group, and then after all you need are the custom categorizers passing in the special field. private void InitializeGroupColumns() { this.gridGroupingControl1.TopLevelGroupOptions.CaptionText = "{Category}x-{RecordCount}"; this.gridGroupingControl1.ChildGroupOptions.CaptionText = "{Category}x-{RecordCount}"; Syncfusion.Grouping.SortColumnDescriptor cd = new SortColumnDescriptor(); cd.Name = "Numero"; cd.Categorizer = new CustomCategorizer(1, "Numero"); this.gridGroupingControl1.TableDescriptor.GroupedColumns.Add(cd); cd = new SortColumnDescriptor(); cd.Name = "2"; cd.Categorizer = new CustomCategorizer(2, "Numero"); this.gridGroupingControl1.TableDescriptor.GroupedColumns.Add(cd); cd = new SortColumnDescriptor(); cd.Name = "3"; cd.Categorizer = new CustomCategorizer(3, "Numero"); this.gridGroupingControl1.TableDescriptor.GroupedColumns.Add(cd); }

Loader.
Up arrow icon