This is a migrated thread and some comments may be shown as answers.

A couple of problems with sorting

1 Answer 79 Views
GridView
This is a migrated thread and some comments may be shown as answers.
George Saveliev
Top achievements
Rank 1
George Saveliev asked on 18 Apr 2011, 08:51 AM
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
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.

1 Answer, 1 is accepted

Sort by
0
Accepted
Alexander
Telerik team
answered on 21 Apr 2011, 08:47 AM
Hello George,

Thank you for contacting us.

I confirm this issue is appears in the Q1 2011 release of RadGridView. We will address it in a next release. In the current version of the control you should add the SortDescriptors at run time to avoid the issue.

The custom sorting mechanism allows sorting of RadGridView rows with higher priority than the applied SortDescriptors. Nevertheless, the triggering of this mechanism requires the existance of a SortDescriptor as you have pointed. It is needed for synchronization of the data and UI layers of the control.

Please do not hesitate to write back if you have additional questions.

Best regards,
Alexander
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
George Saveliev
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Share this question
or