Hi,
is it possible to limit grouping of UltraWinGrid so that it can be grouped by only one column? I want the user to be able to drag a column to grouping area to group by that column. After that, I want to disable other columns to be added to grouping. Thanks for any help!
Best regards Peter
Btw, the reason why I'm trying to do this is that grouping by more than one column doesn't work in my Infragistics2 v10.1 and since we are right before an important release, I cannot afford upgrading (not that I am sure it is solved in newer versions). It looks like this:
Ungroupped:
Grouped by one column (OK):
Grouped by two columns (NOT OK):
Everything is set to default, I just created a new project, put an UltraWinGrid on the form and created some data for it:
using
System.Collections.ObjectModel;using System.Windows.Forms;
namespace
WindowsFormsApplication1{ public partial class Form1 : Form { readonly Collection<Class1> list = new Collection<Class1>();
public Form1() { InitializeComponent();
list.Add(new Class1{ColumnA = "01", ColumnB = "AA", ColumnC = "01", ColumnD = "AA"}); list.Add(new Class1{ColumnA = "02", ColumnB = "AB", ColumnC = "01", ColumnD = "BB"}); list.Add(new Class1{ColumnA = "03", ColumnB = "AC", ColumnC = "02", ColumnD = "CC"}); list.Add(new Class1{ColumnA = "04", ColumnB = "AD", ColumnC = "02", ColumnD = "DD"}); list.Add(new Class1{ColumnA = "01", ColumnB = "BA", ColumnC = "03", ColumnD = "AA"}); list.Add(new Class1{ColumnA = "02", ColumnB = "AA", ColumnC = "03", ColumnD = "BB"}); list.Add(new Class1{ColumnA = "03", ColumnB = "BC", ColumnC = "04", ColumnD = "CC"}); list.Add(new Class1{ColumnA = "04", ColumnB = "AD", ColumnC = "04", ColumnD = "DD"}); list.Add(new Class1{ColumnA = "01", ColumnB = "AA", ColumnC = "05", ColumnD = "AA"});
ultraGrid1.DataSource = list; } }}
If someone could help me with this, I wouldn't need the help with previous post :) Thanks.
P.
Hello Peter,
You could use the following code sample as a possible approach to limit the grouping to one column:
private void ultraGrid1_BeforeSortChange(object sender, Infragistics.Win.UltraWinGrid.BeforeSortChangeEventArgs e) { if (e.SortedColumns.Count > 1) { e.Cancel = true; } }
The reason you get this kind of behavior might be that you are adding different objects using your own class.
You could specify a custom comparer to sort the values using the following property: http://help.infragistics.com/Help/NetAdvantage/WinForms/2011.1/CLR2.0/HTML/Infragistics2.Win.UltraWinGrid.v11.1~Infragistics.Win.UltraWinGrid.UltraGridColumn~GroupByComparer.html.
You could also use: http://help.infragistics.com/Help/NetAdvantage/WinForms/2011.1/CLR2.0/html/Infragistics2.Win.UltraWinGrid.v11.1~Infragistics.Win.UltraWinGrid.UltraGridColumn~GroupByEvaluator.html to perform non-default groups by comparisons.
Please do not hesitate to contact us if you need any additional assistance.
I know this was years ago, but it came up for me now. For others looking to only limit when the "SortedColumns" are actual Group by columns you can try this:
private void ultraGrid_BeforeSortChange(object sender, BeforeSortChangeEventArgs e) { if (e.SortedColumns.All.Cast<UltraGridColumn>().Where(x => x.IsGroupByColumn).Count() > 1) { e.Cancel = true; } }