NoSelection problem

2 posts, 0 answers
  1. Nejchy
    Nejchy avatar
    1 posts
    Member since:
    Nov 2009

    Posted 08 Jan 2013 Link to this post

    I have a combobox which is bound to a list of DictionaryEntries. And I would like that when the form is shown no item is selected (SelectedItem = null).

    Test program
    public partial class Form1 : Form
      {
        public Form1()
        {
          InitializeComponent();
          Bind(GetList());
          Print("Before show");
        }
     
        public void Bind(
          List<DictionaryEntry> p_List)
        {
          radDropDownList1.ValueMember = "Key";
          radDropDownList1.DisplayMember = "Value";
          radDropDownList1.DataSource = p_List;
          radDropDownList1.SelectedIndex = -1;
          radDropDownList1.SelectedItem = null;
          radDropDownList1.SelectedValue = null;
        }
     
        private List<DictionaryEntry> GetList()
        {
          return new List<DictionaryEntry>
                   {
                     new DictionaryEntry(0, "Entry 0"),
                     new DictionaryEntry(1, "Entry 1")
                   };
        }
     
        private void button1_Click(object sender, EventArgs e)
        {
          Bind(GetList());
          Print("rebind");
        }
     
        private void Print(string p_Message)
        {
          richTextBox1.AppendText(String.Format("{2}\nSelectedIndex = {0}\nSelectedValue = {1}\n\n",
                                            radDropDownList1.SelectedIndex, radDropDownList1.SelectedValue, p_Message));
        }
         
        private void Form1_Shown(object sender, EventArgs e)
        {
          Print("OnShow");
        }
     
        private void button2_Click(object sender, EventArgs e)
        {
          Print("Print state");
        }
      }

    The problem is that when the form is shown DropDownList automatically selects first element in the list (SelectedIndex, SelectedItem,.. are updated but Text is not).
    If I rebind after the form is shown DropDownList works correctly.

    Can I bind a list in a way that Form.Show will not select the first element in the list (SelectedItem = null)?
  2. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 10 Jan 2013 Link to this post

    Hello Nejchy,

    We are aware of this issue and it has been logged to our Public Issue Tracking System. It will be addressed in our next internal build.

    As a workaround you can set the selected index this way:
    this.radDropDownList1.SelectedIndex = -1;
    this.radDropDownList1.ListElement.DataLayer.DataView.MoveCurrentToPosition(-1);

    Thank you for your time and cooperation.

    All the best,
    Peter
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top