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

Setting SelectionMode and SortStyle at desing time show false selections in some situations

4 Answers 59 Views
ListControl
This is a migrated thread and some comments may be shown as answers.
Holger Boskugel
Top achievements
Rank 2
Holger Boskugel asked on 29 May 2012, 04:44 PM
Hello,

I observed a behavior of RadListControl which shows false results. I could reproduce it with this code:

using System.Windows.Forms;
using Telerik.WinControls.Enumerations;
using Telerik.WinControls.UI;
 
namespace TestListboxSortAnSelection
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
 
            this.radListControl1.SelectionMode = SelectionMode.MultiExtended;
            this.radListControl1.SortStyle = SortStyle.Ascending;
 
            this.radListControl1.Items.Add(new RadListDataItem("Test 1"));
            this.radListControl1.Items.Add(new RadListDataItem("Test 3") { Selected = true });
            this.radListControl1.Items.Add(new RadListDataItem("Test 2") { Selected = true });
        }
 
        private void radButton1_Click(object sender, System.EventArgs e)
        {
            MessageBox.Show(string.Concat("Selected items: ",
                                          this.radListControl1.SelectedItems.Count));
        }
 
 
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.radListControl1 = new Telerik.WinControls.UI.RadListControl();
            this.radButton1 = new Telerik.WinControls.UI.RadButton();
            ((System.ComponentModel.ISupportInitialize)(this.radListControl1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.radButton1)).BeginInit();
            this.SuspendLayout();
            //
            // radListControl1
            //
            this.radListControl1.CaseSensitiveSort = true;
            this.radListControl1.ItemHeight = 18;
            this.radListControl1.Location = new System.Drawing.Point(12, 12);
            this.radListControl1.Name = "radListControl1";
            this.radListControl1.Size = new System.Drawing.Size(431, 312);
            this.radListControl1.TabIndex = 0;
            this.radListControl1.Text = "radListControl1";
            //
            // radButton1
            //
            this.radButton1.Location = new System.Drawing.Point(313, 330);
            this.radButton1.Name = "radButton1";
            this.radButton1.Size = new System.Drawing.Size(130, 24);
            this.radButton1.TabIndex = 1;
            this.radButton1.Text = "radButton1";
            this.radButton1.Click += new System.EventHandler(this.radButton1_Click);
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(455, 366);
            this.Controls.Add(this.radButton1);
            this.Controls.Add(this.radListControl1);
            this.Name = "Form1";
            this.Text = "Form1";
            ((System.ComponentModel.ISupportInitialize)(this.radListControl1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.radButton1)).EndInit();
            this.ResumeLayout(false);
 
        }
 
        private Telerik.WinControls.UI.RadListControl radListControl1;
        private Telerik.WinControls.UI.RadButton radButton1;
    }
}

If SelectionMode is None, all works fine. Changing to One and SortStyle to Ascending it shows 2 selected items, but only 1 is selected. If SortStyle is Descending and Test 1 and 2 preselected then it shows also 2 selected items with one selected in list. Similar results occures with SelectionMode MultiSimple and MultiExtended. With SortStyle Ascending only 1 item is select on view and list. On SortStyle Descending it changes to 3 items on view and list.

The work around of this bug?! is to set SortStyle after adding the items to Items list (in code, not during design time).


Regards from Leipzig

Holger Boskugel

4 Answers, 1 is accepted

Sort by
0
Holger Boskugel
Top achievements
Rank 2
answered on 29 May 2012, 05:47 PM
@Telerik Admins: Please move this thread to "DropDownList and ListControl"
0
Peter
Telerik team
answered on 31 May 2012, 01:29 PM
Hello Holger,

Thank you for reporting this to us.

I would like to suggest manipulating the selection and sort order after adding the items into RadListControl .
I have updated your Telerik point for the cooperation.

Do not hesitate to contact us if you have other questions.

All the best,
Peter
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Holger Boskugel
Top achievements
Rank 2
answered on 31 May 2012, 05:07 PM
Hello again,

I have a next problem under this topic, not only the display of items makes trouble also selection in a sorted ListControl.

Work around is sorting items before adding to Items collection and switch off sorting (SortStyle = None).


Regards from Leipzig

Holger
0
Peter
Telerik team
answered on 05 Jun 2012, 08:48 AM
Hi Holger,

Thank you for bringing this to our attention and for sharing your workaround with the community.

All the best,
Peter
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Tags
ListControl
Asked by
Holger Boskugel
Top achievements
Rank 2
Answers by
Holger Boskugel
Top achievements
Rank 2
Peter
Telerik team
Share this question
or