however now when i select an item in the combobox either by pressing down or by selecting an item with the mouse it then selects that item and puts the text into the radcombo.text field, however it is my understanding that the event that fires this off is the selectedvalue changed? however the text changes and txtchanged is run before selectedvaluechanged and this is causing problems for me? is this the correct order of events firing and if so how can i get around this ?
here is sample of similar code
private void rcboInfo_TextChanged(object sender, EventArgs e) |
{ |
List<InfoComboDetails> allInfos = controller.GetInfoBySearchString(searchstr); |
foreach (info i in allInfos) |
{ |
RadComboBoxItem rcbi = new RadComboBoxItem(i.Column1 + " - " + i.colum2 , i.ID); |
rcboInfo.Items.Add(rcbi); |
} |
} |
private void rcboInfo_SelectedValueChanged(object sender, EventArgs e) |
{ |
rcboinfo2.SelectedValue = controller.GetInfo2ByInfoID((int)rcboInfo.SelectedValue).ID; |
} |
6 Answers, 1 is accepted
please help
In the standard combobox the TextChanged event is fired before the ValueChanged event and in this regard RadCombobox works correctly. Your code is predicated on a wrong assumption and unfortunately it has to be changed. Populating data in TextChanged event is a hack in general and should be avoided.
Please extend a bit on your scenario so that we can think of a work-around that actually works for you. As far as I understand, you need to present a subset of all your data at any given moment. Do you think that you can use two comboboxes. When the first subset is selected in the first combobox the second one gets updated? I am looking forward to your reply.
Sincerely yours,
Nick
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
The problem has come about from a requirement to do list item filtering in a RadComboBox; the principle of which is as follows: The RadComboBox is text-editable such that a user may move their carat into the text field portion of the combo box and start to type. As the user types, the list of RadComboBoxItems in its Items collection will update to reflect values appropriate with the user’s input text.
This portion works correctly and a user can type into the box and have the Items collection of the combo box update from the RadComboBox’s TextChanged event. In the code that handle’s this event, all values passed into the event as well as the instantiated RadComboBox and its associated Items collection are traversable and correct. It needs to be stated, however, that this TextChanged event fires twice; first with the correct data being send to the event handler and then, immediately thereafter, a second time with a bunce of blank Strings and null values being passed through. We have coded around this double event firing.
However, a second event is also required that will cater for the user actually making a selection from the list of RadComboBoxItems that are available at the time and such a selection will be made through mouse action on the drop down list presented to them.
We have unsuccessfully attempted to use both the exposed SelectedValueChanged event and the SelectedIndexChanged event handlers for these controls and in both situations the scenario is the same. No matter what is done, the earlier TextChanged event fires (twice, once with garbage) before the SelectedValueChanged event fires. Stepping through the code shows some interesting behaviour in the way in which the event synchronicity is handled; the first TextChanged event fires and executes until a call to a separate method is required, at which point the second event propagates and starts processing. After the second TextChanged event is processed the SelectedValueChanged event is fired (again, twice) and that event will complete execution before the first TextChanges event un-pauses and finally completes.
The problem thus is as follows: TextChanged is an event that is used to rebuild the Items collection and SelectedIndexChanged is an event that is used to populate the rest of the form based on the user’s choice. Simply put, the TextChanges event firing before a SelectedIndexChanged event is causing the collection to be rebuilt and thus causing the RadComboBox control to lose its state and the ever important SelectedValue property that we hope to retrieve there.
Thank you for contacting me back.
Can you avoid rebuilding the combobox items in the following way:
private void radComboBox1_TextChanged(object sender, EventArgs e) |
{ |
if (this.radComboBox1.Text.ToLower() == "abc") |
{ |
this.radComboBox1.Items.Clear(); |
RadComboBoxItem rcbi = new RadComboBoxItem(); |
rcbi.Text = "New Item"; |
radComboBox1.Items.Add(rcbi); |
RadComboBoxItem rcbi2 = new RadComboBoxItem("Second new item"); |
radComboBox1.Items.Add(rcbi2); |
} |
if (this.radComboBox1.Text.ToLower() == "cba") |
{ |
this.radComboBox1.Items.Clear(); |
RadComboBoxItem rcbi = new RadComboBoxItem(); |
rcbi.Text = "New Item 2"; |
radComboBox1.Items.Add(rcbi); |
RadComboBoxItem rcbi2 = new RadComboBoxItem("Second new item 2"); |
radComboBox1.Items.Add(rcbi2); |
} |
} |
private void radComboBox1_SelectedIndexChanged(object sender, EventArgs e) |
{ |
if (this.radComboBox1.SelectedIndex == -1) { |
return; |
} |
Console.WriteLine(this.radComboBox1.SelectedIndex); |
} |
private void radComboBox1_SelectedValueChanged(object sender, EventArgs e) |
{ |
if (this.radComboBox1.SelectedText == "abc" || |
this.radComboBox1.SelectedText == "cba") |
return; |
Console.WriteLine(this.radComboBox1.SelectedText); |
} |
I confirm the double firing of events and we are going to address the issue in one of our future releases. I have updated your Telerik points for bringing our attention to this matter.
Please write me back with comments on the source I gave.
All the best,
Nick
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
thanks very much