This is a migrated thread and some comments may be shown as answers.
NoSelection problem
1 Answer 32 Views
This is a migrated thread and some comments may be shown as answers.
Nejchy
Top achievements
Rank 1
Nejchy asked on 08 Jan 2013, 02:46 PM
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)?

1 Answer, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 10 Jan 2013, 02:17 PM
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.
Asked by
Nejchy
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or