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

Selecting first item after binding combo

4 Answers 106 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Mansi
Top achievements
Rank 1
Mansi asked on 03 Mar 2010, 06:16 AM
Hi,

I have one radcomobobox, on its selectedindexchanged event, I am binding it with new values.
It is ok when I bind it first time, it do show the first item selected. But when the selectedindexchanged event fires, it still shows the previously selected item (only text, when I click on comobo, it shows the new item selected), even though I assign selected index every time on binding.

Below is a code of binding.

  for (i = 0; i <= dtable.Rows.Count - 1; i++) 
     { 
       DDEvent.Items.Add(new RadComboBoxItem("text", "value"); 
     } 
   DDEvent.SelectedIndex = 0 
 
 

I tried this too after the above code, but still not done.

      DDEvent.SelectedItem.Text = DDEvent.Items(0).Text

4 Answers, 1 is accepted

Sort by
0
robertw102
Top achievements
Rank 1
answered on 03 Mar 2010, 03:36 PM
I don't understand your situation. Are you saying that you bind the values of the RadComboBox in its SelectedIndexChanged event? I don't understand why you would be binding the RadComboBoxes values in that event.

Also, the reason it won't show the item you set as the SelectedIndex is because after the event finishes, I believe it then sets the index that was selected as the selected item or the selected text.
0
Mansi
Top achievements
Rank 1
answered on 04 Mar 2010, 06:13 AM
Hi,
Thanks for the reply.
I explain again. Find attached image.

I have two combos. On the selectedindexchanged event of the first comobo, I am filling the second comobo and selecting the first item of the filled comobo.

First time I do this on page load, and everything works fine. But then, when I change the item in first comobo, it fills the second combo properly.
But in second combo after fill, it still shows the text, which was previously selected, not the first item from the filled items. And I need to select it only by its index, which should be 0.
0
Accepted
robertw102
Top achievements
Rank 1
answered on 04 Mar 2010, 02:56 PM
Does your second combobox have the AllowCustomText="true" property set? It sounds like that may be the reason the text still persists after you select the next item or maybe I'm wrong. Either way, why not try clearing the text of the second combobox before populating it and see if that helps.

Like so:
RadComboBox2.Text = ""
0
Mansi
Top achievements
Rank 1
answered on 05 Mar 2010, 06:16 AM
Hi,

Thanks, It worked.

I didn't set AllowCustomText="true".

Before binding I was clearing items of combo, but was not setting the text.

RadComboBox2.Text = "" worked.
Tags
ComboBox
Asked by
Mansi
Top achievements
Rank 1
Answers by
robertw102
Top achievements
Rank 1
Mansi
Top achievements
Rank 1
Share this question
or