Hello!
I found a couple of problems with sorting in the latest WinForms RadGridView (2011.1.11.315). I use Visual Studio 2008 with .NET 3.5.
I have created a single form with a RadGridView.
Form1.cs
I found a couple of problems with sorting in the latest WinForms RadGridView (2011.1.11.315). I use Visual Studio 2008 with .NET 3.5.
I have created a single form with a RadGridView.
Form1.cs
using System.Collections.Generic; using System.Windows.Forms; namespace Test { public partial class Form1 : Form { public Form1() { InitializeComponent(); List<DataItem> list = new List<DataItem>(); list.Add(new DataItem() { Name = "Item 1" }); list.Add(new DataItem() { Name = "Item 3" }); list.Add(new DataItem() { Name = "Item 2" }); radGridView1.DataSource = list; } } public class DataItem { public string Name { get; set; } } } Form1.Designer.cs
namespace Test { partial class Form1 { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { Telerik.WinControls.UI.GridViewTextBoxColumn gridViewTextBoxColumn1 = new Telerik.WinControls.UI.GridViewTextBoxColumn(); Telerik.WinControls.Data.SortDescriptor sortDescriptor1 = new Telerik.WinControls.Data.SortDescriptor(); this.radGridView1 = new Telerik.WinControls.UI.RadGridView(); ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.radGridView1.MasterTemplate)).BeginInit(); this.SuspendLayout(); // // radGridView1 // this.radGridView1.BackColor = System.Drawing.SystemColors.Control; this.radGridView1.Cursor = System.Windows.Forms.Cursors.Default; this.radGridView1.Dock = System.Windows.Forms.DockStyle.Fill; this.radGridView1.EnableCustomSorting = true; this.radGridView1.Font = new System.Drawing.Font("Segoe UI", 8.25F); this.radGridView1.ForeColor = System.Drawing.SystemColors.ControlText; this.radGridView1.ImeMode = System.Windows.Forms.ImeMode.NoControl; this.radGridView1.Location = new System.Drawing.Point(0, 0); // // radGridView1 // gridViewTextBoxColumn1.FieldName = "Name"; gridViewTextBoxColumn1.FormatString = ""; gridViewTextBoxColumn1.HeaderText = "Name"; gridViewTextBoxColumn1.Name = "Name"; this.radGridView1.MasterTemplate.Columns.AddRange(new Telerik.WinControls.UI.GridViewDataColumn[] { gridViewTextBoxColumn1}); sortDescriptor1.PropertyName = "Name"; this.radGridView1.MasterTemplate.SortDescriptors.AddRange(new Telerik.WinControls.Data.SortDescriptor[] { sortDescriptor1}); this.radGridView1.Name = "radGridView1"; this.radGridView1.RightToLeft = System.Windows.Forms.RightToLeft.No; this.radGridView1.Size = new System.Drawing.Size(284, 264); this.radGridView1.TabIndex = 0; this.radGridView1.Text = "radGridView1"; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(284, 264); this.Controls.Add(this.radGridView1); this.Name = "Form1"; this.Text = "Form1"; ((System.ComponentModel.ISupportInitialize)(this.radGridView1.MasterTemplate)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).EndInit(); this.ResumeLayout(false); } #endregion private Telerik.WinControls.UI.RadGridView radGridView1; } } The grid sorting is set in the Property Builder. But when line
((System.ComponentModel.ISupportInitialize)(this.radGridView1)).EndInit();is executed, the SortDescriptors collection is cleared and the grid becomes unsortable. This worked well in v.2010.3.10.1215.
Another problem concerns the custom sorting. I found that the CustomSorting handler is not called if the SortDescriptors collection is empty. I think this is not correct behavior, because the custom sorting logic is coded explitly and it should not depend on the grid sort descriptiors. If we note the first problem listed above, the CustomSorting handler is not called until the SortDescriptors collection is explicitly populated with the application code, or the column header is clicked by user.
Thank you.