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

Programmatic sort broken in Q1 2011

2 Answers 46 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Cat
Top achievements
Rank 1
Cat asked on 02 May 2011, 08:26 PM
I did a search in the forums and in PITS but didn't find any mention of this. However, I have code that worked with Q3 2010, but no longer works with Q1 2011. You can repro this using the code below:

using System.ComponentModel;
using System.Windows.Forms;
using Telerik.WinControls.Data;
using Telerik.WinControls.UI;
  
namespace PropertyGridExample
{
    public class GridViewFactory
    {
        public RadGridView CreateGridView()
        {
            // Setup gridview with default options
            RadGridView gvResults = new RadGridView();
            gvResults.Dock = DockStyle.Fill;
            //gvResults.AllowAutoSizeColumns = true;
            gvResults.ReadOnly = true;
            gvResults.Text = "Test";
            gvResults.Name = "SearchResults";
            gvResults.EnableSorting = true;
            gvResults.MasterTemplate.EnableSorting = true;
  
            // Setup MasterTemplate
            gvResults.MasterTemplate.AllowAddNewRow = false;
            gvResults.MasterTemplate.AutoGenerateColumns = false;
            gvResults.MasterTemplate.Tag = "Test Template";
  
            gvResults.DataSource = null;
  
            gvResults.TableElement.BeginUpdate();
            gvResults.MasterTemplate.Columns.Clear();
  
            // Setup Columns
            GridViewTextBoxColumn column = new GridViewTextBoxColumn();
            column.Name = "Title";
            column.HeaderText = "Title";
            column.FieldName = "Title";
            column.MinWidth = 50;
            column.MaxWidth = 250;
            column.AutoSizeMode = BestFitColumnMode.DisplayedDataCells;
  
            gvResults.MasterTemplate.Columns.Add(column);
  
            GridViewTextBoxColumn column1 = new GridViewTextBoxColumn();
            column1.Name = "Countries";
            column1.HeaderText = "Countries";
            column1.FieldName = "Countries";
            column1.MinWidth = 50;
            column1.MaxWidth = 250;
            column1.AutoSizeMode = BestFitColumnMode.DisplayedDataCells;
  
            gvResults.MasterTemplate.Columns.Add(column1);
  
            GridViewTextBoxColumn column2 = new GridViewTextBoxColumn();
            column2.Name = "Sites";
            column2.HeaderText = "Sites";
            column2.FieldName = "Sites";
            column2.MinWidth = 50;
            column2.MaxWidth = 250;
            column2.AutoSizeMode = BestFitColumnMode.DisplayedDataCells;
  
            gvResults.MasterTemplate.Columns.Add(column2);
  
            gvResults.TableElement.EndUpdate(false);
  
            // Set the Datasource (Can be any object collection)
            gvResults.DataSource = DataFactoryClass.GetData();
  
            SortDescriptor descriptor = new SortDescriptor();
            descriptor.PropertyName = "Title";
            descriptor.Direction = ListSortDirection.Descending;
            gvResults.SortDescriptors.Add(descriptor);
  
            return gvResults;
        }
    }
}

DataSource can be any collection of objects; I was using a three property object collection (evidenced by the column creations) for simplicity. When this RadGridView is attached to a form as a control, it will *not* sort on the title as suggested, using the current assemblies. Reverting to the older Q3 2010 assemblies works however.

Unfortunately I am not able to revert our code back to the old assemblies, as the new assemblies fix several other major bugs present in the Q3 2010 version. Is there a workaround available or a fix planned soon?

EDIT: (I also just put this in as a support issue.)

2 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 03 May 2011, 07:28 AM
Hello Cat,

Yes... You are right about this, but as a workaround you can add twice the same SortDescriptor and it will work.

var sortDescriptor = new Telerik.WinControls.Data.SortDescriptor("Name", ListSortDirection.Descending);
radGridView1.SortDescriptors.Add(sortDescriptor);
radGridView1.SortDescriptors.Add(sortDescriptor);

I'm glad you have opened a support ticket, maybe you will receive more info from telerik there.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga

Telerik WinForms MVP
0
Alexander
Telerik team
answered on 03 May 2011, 01:22 PM
Hello Cat,

Thank you for reporting this issue. I have added it to our PITS. We will address it in a next release. Your Telerik points have been updated.

As a work-around, you can define the SortOrder of the column instead of adding a SortDescriptor. In your example you should replace the following lines of code:
SortDescriptor descriptor = new SortDescriptor();
descriptor.PropertyName = "Title";
descriptor.Direction = ListSortDirection.Descending;
gvResults.SortDescriptors.Add(descriptor);

with:
column.SortOrder = RadSortOrder.Descending;

I hope it helps.

Best regards,
Alexander
the Telerik team
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
Tags
GridView
Asked by
Cat
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Alexander
Telerik team
Share this question
or