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

Sort descriptors not working after upgrading to 2010.3 SP1

8 Answers 138 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 07 Jan 2011, 03:20 PM
Hi there. 

A few days ago, I upgraded from version 2010.3.1109 of the Windows Forms controls to version 2010.3.1215 (SP1). This was done to fix an issue with the RadButton.

However, now my sort descriptors I have added to a RadGridView are not being respected. Below is the code I am using which was working before the upgrade. 

private void sortGrid()
        {
            int sortOrder = byBradFordRadioButton.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On ? 0 : 1;
            dataGrid.SortDescriptors.Clear();
 
            if ( sortOrder == 0 )
            {
                dataGrid.SortDescriptors.Add(new SortDescriptor("Bradford Factor", ListSortDirection.Descending));
 
                // select the first row
                dataGrid.setSelectedRowIndex(0);
            }
            else
            {
                dataGrid.SortDescriptors.Add(new SortDescriptor("Employee", ListSortDirection.Ascending));
            }
        }

Any clues on a workaround for this?

8 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 08 Jan 2011, 12:36 PM
Hi Adam,

I haven't noticed any issues with Sort Descriptors in this version.  I notice though one of the sort descriptors you are adding is BradFord Factor" (with a space). Is this the name of you column? If you can confirm, and you are still having issues, I shall putotogether a small sample for you to try
thanks
Richard
0
Adam
Top achievements
Rank 1
answered on 10 Jan 2011, 12:29 PM
I have verified that the name of the column and the parameter passed to SortDescriptors.Add() match exactly and the sort descriptors are not working using the latest version of the controls. 
0
Richard Slade
Top achievements
Rank 2
answered on 10 Jan 2011, 12:41 PM
Hello Adam,

Please can you try this basic example in a new project and let me know if it works correctly for you? If so, then please post an exmaple that demonstrates your issue and I'll be happy to take a look at it for you.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls.UI;
using Telerik.WinControls;
using Telerik.WinControls.Data;
  
  
namespace RadGridView_Basic_C
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            FillTelerikGrid();
        }
  
        private void FillTelerikGrid()
        {
            List<MyObject> source = new List<MyObject>();
            source.Add(new MyObject() { Id = "1", Name = "row1, level1"});
            source.Add(new MyObject() { Id = "2", Name = "row2, level1"});
            source.Add(new MyObject() { Id = "3", Name = "row1, level1"});
            source.Add(new MyObject() { Id = "4", Name = "row2, level1"});
            source.Add(new MyObject() { Id = "5", Name = "row1, level1"});
            source.Add(new MyObject() { Id = "6", Name = "row2, level1"});
            source.Add(new MyObject() { Id = "7", Name = "row1, level1"});
            source.Add(new MyObject() { Id = "8", Name = "row2, level1"});
  
            this.radGridView1.DataSource = source;
  
            this.radGridView1.SortDescriptors.Clear();
            this.radGridView1.SortDescriptors.Add(new SortDescriptor("Name", ListSortDirection.Descending));
  
        
  
    }
  
    class MyObject 
    
        public string Id { get; set; } 
        public string Name { get; set; } 
    }
  }

Regards,
Richard
0
Adam
Top achievements
Rank 1
answered on 10 Jan 2011, 01:02 PM
Your posted example works correctly for me. 

The grid I am using in the original post is a user control which inherits from the Telerik RadGrid. It has the following properties set:

AutoGenerateColumns = false;
            AllowAddNewRow = false;
            AllowDeleteRow = false;
            AllowEditRow = false;
 
            // font style for the header
            Font = new Font("Century Gothic", 8.25f, FontStyle.Bold);
 
            // set default colour theme
            ThemeClassName = "Telerik.WinControls.UI.RadGridView";
 
            // set scrollbar behaviour
            HorizontalScrollState = ScrollState.AutoHide;
            VerticalScrollState = ScrollState.AutoHide;
 
            // show filter icon in column headers
            EnableFiltering = true;
            ShowFilteringRow = false;
            ShowHeaderCellButtons = true;
 
            // disable the header row
            ShowRowHeaderColumn = false;

I am thinking I need EnableSorting = true; as well, but this does not explain why the sort descriptors work as desired in the previous version of the controls. 
0
Richard Slade
Top achievements
Rank 2
answered on 10 Jan 2011, 01:17 PM
Hello Adam,

I am still unable to replicate your issue. My next thought is that you have lost the event handler, or are not handling the event for your radio button toggle state changed which would mean that your sortGrid() method is not being called.
If you can check this, and if it is not the issue, please post a full example that replicates the issue so I can take a look at this for you.
Many thanks
Richard
0
Richard Slade
Top achievements
Rank 2
answered on 10 Jan 2011, 01:23 PM
For reference, here is an example using your grid settings, plus your sort method. It's just a RadGridView and Two RadRadioButtons on a form.

Main File
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls.UI;
using Telerik.WinControls;
using Telerik.WinControls.Data;
  
  
namespace RadGridView_Basic_C
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            FillTelerikGrid();
        }
  
        private void FillTelerikGrid()
        {
            this.radGridView1.AutoGenerateColumns = false;
            this.radGridView1.AllowAddNewRow = false;
            this.radGridView1.AllowDeleteRow = false;
            this.radGridView1.AllowEditRow = false;
            this.radGridView1.HorizontalScrollState = ScrollState.AutoHide;
            this.radGridView1.VerticalScrollState = ScrollState.AutoHide;
  
            // show filter icon in column headers
            this.radGridView1.EnableFiltering = true;
            this.radGridView1.ShowFilteringRow = false;
            this.radGridView1.ShowHeaderCellButtons = true;
  
            // disable the header row
            this.radGridView1.ShowRowHeaderColumn = false;
  
            GridViewDecimalColumn colId = new GridViewDecimalColumn("Id");
            GridViewTextBoxColumn colName = new GridViewTextBoxColumn("Name");
  
            this.radGridView1.Columns.Add(colId);
            this.radGridView1.Columns.Add(colName);
  
            List<MyObject> source = new List<MyObject>();
            source.Add(new MyObject() { Id = "1", Name = "row1, level1"});
            source.Add(new MyObject() { Id = "2", Name = "row2, level1"});
            source.Add(new MyObject() { Id = "3", Name = "row1, level1"});
            source.Add(new MyObject() { Id = "4", Name = "row2, level1"});
            source.Add(new MyObject() { Id = "5", Name = "row1, level1"});
            source.Add(new MyObject() { Id = "6", Name = "row2, level1"});
            source.Add(new MyObject() { Id = "7", Name = "row1, level1"});
            source.Add(new MyObject() { Id = "8", Name = "row2, level1"});
  
            this.radGridView1.DataSource = source;
  
            radRadioButton1.ToggleState = Telerik.WinControls.Enumerations.ToggleState.On;
  
        }
  
  
        private void sortGrid()
        {
            int sortOrder = this.radRadioButton1.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On ? 0 : 1;
            this.radGridView1.SortDescriptors.Clear();
  
            if (sortOrder == 0)
            {
                this.radGridView1.SortDescriptors.Add(new SortDescriptor("Name", ListSortDirection.Descending));
  
                // select the first row
                this.radGridView1.Rows[0].IsSelected = true;
            }
            else
            {
                this.radGridView1.SortDescriptors.Add(new SortDescriptor("Id", ListSortDirection.Ascending));
            }
        }
  
        private void radRadioButton1_ToggleStateChanged(object sender, StateChangedEventArgs args)
        {
            sortGrid();
        }
  
  
    }
  
    class MyObject 
    
        public string Id { get; set; } 
        public string Name { get; set; } 
    }
  }

Designer File
namespace RadGridView_Basic_C
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components;
  
        /// <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()
        {
            this.radGridView1 = new Telerik.WinControls.UI.RadGridView();
            this.radRadioButton1 = new Telerik.WinControls.UI.RadRadioButton();
            this.radRadioButton2 = new Telerik.WinControls.UI.RadRadioButton();
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).BeginInit();
            this.radGridView1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.radRadioButton1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.radRadioButton2)).BeginInit();
            this.SuspendLayout();
            // 
            // radGridView1
            // 
            this.radGridView1.Controls.Add(this.radRadioButton2);
            this.radGridView1.Controls.Add(this.radRadioButton1);
            this.radGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.radGridView1.Location = new System.Drawing.Point(0, 0);
            this.radGridView1.Name = "radGridView1";
            this.radGridView1.Size = new System.Drawing.Size(457, 411);
            this.radGridView1.TabIndex = 0;
            this.radGridView1.Text = "radGridView1";
            // 
            // radRadioButton1
            // 
            this.radRadioButton1.Location = new System.Drawing.Point(179, 364);
            this.radRadioButton1.Name = "radRadioButton1";
            this.radRadioButton1.Size = new System.Drawing.Size(110, 18);
            this.radRadioButton1.TabIndex = 0;
            this.radRadioButton1.Text = "radRadioButton1";
            this.radRadioButton1.ToggleStateChanged += new Telerik.WinControls.UI.StateChangedEventHandler(this.radRadioButton1_ToggleStateChanged);
            // 
            // radRadioButton2
            // 
            this.radRadioButton2.Location = new System.Drawing.Point(295, 364);
            this.radRadioButton2.Name = "radRadioButton2";
            this.radRadioButton2.Size = new System.Drawing.Size(110, 18);
            this.radRadioButton2.TabIndex = 1;
            this.radRadioButton2.Text = "radRadioButton2";
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(457, 411);
            this.Controls.Add(this.radGridView1);
            this.Name = "Form1";
            this.Text = "Form1";
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).EndInit();
            this.radGridView1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.radRadioButton1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.radRadioButton2)).EndInit();
            this.ResumeLayout(false);
  
        }
  
        #endregion
  
        private Telerik.WinControls.UI.RadGridView radGridView1;
        private Telerik.WinControls.UI.RadRadioButton radRadioButton2;
        private Telerik.WinControls.UI.RadRadioButton radRadioButton1;
    }
}
Regards,
Richard
0
Adam
Top achievements
Rank 1
answered on 10 Jan 2011, 02:30 PM
Just fixed this issue!

The grid on the form had the EnableCustomSorting property set to 'True' which was preventing the sort descriptors from working. Also, with this property set, clicking on a grid column header was not sorting the contents by that column. 
0
Richard Slade
Top achievements
Rank 2
answered on 10 Jan 2011, 02:33 PM
Glad you have this sorted, Adam.
All the best
Richard
Tags
GridView
Asked by
Adam
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Adam
Top achievements
Rank 1
Share this question
or