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.
Unfortunately, activation email could not send to your email. Please try again.

GridGroupingControl - Sorting Related Columns together

Thread ID:

Created:

Updated:

Platform:

Replies:

36995 Nov 14,2005 01:15 PM Nov 15,2005 01:43 PM Windows Forms 5
loading
Tags: GridControl
Badri Rajani Kanth
Asked On November 14, 2005 01:15 PM

Hi All, I have a grid grouping control, in which each row has an integer valued column. Sometimes data in this column can be empty. When this data falls in a range, I will display then in green color. For some other range yellow. And for last(higher) range red. The columns with empty values are assumed to be high valued and will be displayed in red color. Thus normally, columns(in each row) with same color will appear one below another. Now the problem is, when user sorts on the column, the empty valued columns (red colored)are displayed on the top. And then green, yellow and again Red. Thus user sees two sets of red colored columns. I have display all red columns together irrespective of column value. means I have to sort on cell back color instead of column value! Can any body give me some input. I am trying with adding some inner values to column and sort by those values. Still trying. Thanks and Regards Rajani Kanth

Administrator [Syncfusion]
Replied On November 14, 2005 01:36 PM

You can add a custom IComparer to the SortColumnDescriptor for this column. You do this by setting the Comparer property on the SortColumnDescriptor. In your custom IComparer object, you can sort based on any criteria you choose including any color criteria on the record value.

Badri Rajani Kanth
Replied On November 15, 2005 04:45 AM

Thank you..Can you give me some code sample if possible? Rgds Rajani Kanth >You can add a custom IComparer to the SortColumnDescriptor for this column. You do this by setting the Comparer property on the SortColumnDescriptor. In your custom IComparer object, you can sort based on any criteria you choose including any color criteria on the record value.

Administrator [Syncfusion]
Replied On November 15, 2005 05:47 AM

Here is a sample. http://www.syncfusion.com/Support/user/uploads/GGC_CustomSort_caa7f55b.zip

Badri Rajani Kanth
Replied On November 15, 2005 01:37 PM

Hi, I think the link & attachement is not for this example. It does not contain GGC. Rgds Rajani Kanth >Here is a sample. > >http://www.syncfusion.com/Support/user/uploads/GGC_CustomSort_caa7f55b.zip > >

Administrator [Syncfusion]
Replied On November 15, 2005 01:43 PM

It appears to be the proper link to me. Here is the content of the form1.cs file that I see. using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using Syncfusion.Windows.Forms.Grid.Grouping; using Syncfusion.Windows.Forms.Grid; using Syncfusion.Grouping; namespace GGC_CustomSort { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private Syncfusion.Windows.Forms.Grid.Grouping.GridGroupingControl gridGroupingControl1; private System.Windows.Forms.Label label1; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.gridGroupingControl1 = new Syncfusion.Windows.Forms.Grid.Grouping.GridGroupingControl(); this.label1 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.gridGroupingControl1)).BeginInit(); this.SuspendLayout(); // // gridGroupingControl1 // this.gridGroupingControl1.BackColor = System.Drawing.SystemColors.Window; this.gridGroupingControl1.Location = new System.Drawing.Point(32, 48); this.gridGroupingControl1.Name = "gridGroupingControl1"; this.gridGroupingControl1.Size = new System.Drawing.Size(488, 376); this.gridGroupingControl1.TabIndex = 0; this.gridGroupingControl1.Text = "gridGroupingControl1"; this.gridGroupingControl1.VersionInfo = "3.301.0.0"; // // label1 // this.label1.Location = new System.Drawing.Point(80, 16); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(400, 23); this.label1.TabIndex = 1; this.label1.Text = "Col2 sorts on the value mod 3."; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(552, 454); this.Controls.Add(this.label1); this.Controls.Add(this.gridGroupingControl1); this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.gridGroupingControl1)).EndInit(); this.ResumeLayout(false); } #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new Form1()); } private void Form1_Load(object sender, System.EventArgs e) { #region Get the DataSource DataTable dt = new DataTable("MyTable"); int nCols = 4; int nRows = 20; Random r = new Random(123345345); for(int i = 0; i < nCols; i++) dt.Columns.Add(new DataColumn(string.Format("Col{0}", i), typeof(int))); for(int i = 0; i < nRows; ++i) { DataRow dr = dt.NewRow(); for(int j = 0; j < nCols; j++) dr[j] = r.Next(10); dt.Rows.Add(dr); } #endregion this.gridGroupingControl1.DataSource = dt; //use this event to hook into the sorting to use custom comparer this.gridGroupingControl1.TableDescriptor.SortedColumns.Changing += new Syncfusion.Collections.ListPropertyChangedEventHandler(SortedColumns_Changing); //not needed for the custom sorting, just to display the colored rows //use event to color row based on [Col2] Mod 2 this.gridGroupingControl1.TableControlPrepareViewStyleInfo += new GridTableControlPrepareViewStyleInfoEventHandler(gridGroupingControl1_TableControlPrepareViewStyleInfo); } //used to set up custom comparer private void SortedColumns_Changing(object sender, Syncfusion.Collections.ListPropertyChangedEventArgs e) { SortColumnDescriptor sd = e.Item as SortColumnDescriptor; if(sd != null && sd.Name == "Col2" && e.Action == Syncfusion.Collections.ListPropertyChangedType.Add) { sd.Comparer = new CustomComparer(); } } //used to color rows based on [Col2] Mod 3 private void gridGroupingControl1_TableControlPrepareViewStyleInfo(object sender, GridTableControlPrepareViewStyleInfoEventArgs e) { GridTableCellStyleInfo style = e.Inner.Style as GridTableCellStyleInfo; if(style.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell || style.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell) { GridRecordRow recRow = style.TableCellIdentity.DisplayElement as GridRecordRow; if(recRow != null) { object o = recRow.ParentRecord.GetValue("Col2"); if( o != null && o.ToString().Length > 0) { int modValue = (int)o % 3; switch((int)o % 3) { case 0: style.BackColor = Color.Red; break; case 1: style.BackColor = Color.Blue; break; case 2: style.BackColor = Color.Green; break; default: break; } } } } } } public class CustomComparer : IComparer { public CustomComparer() { } #region IComparer Members public int Compare(object x, object y) { int c; if(x == null && y == null) c = 0; else if(x == null) c = -1; else if(y == null) c = 1; else { int ix = (int) x % 3; int iy = (int) y % 3; if(ix < iy) c = -1; else if(ix > iy) c = 1; else { c = 0; } } return c; } #endregion } }

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;