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

RAD Combobox intermittentent Errors for Non Existing Values

3 Answers 157 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 27 Oct 2008, 09:53 AM
Hi,

We have sometimes been getting errors when we assign the selected value of a RAD combobox to a value that does not exist within the combobox. Firstly we do have a workaround for this however:
 - we would like to know why the error occurs intermittentently and whether we can permently fix problem without the extra workaround code
 or
- how to turn of the function to set the selected index to 0 if the combobox is assigned a non-existent value so we would see an error everytime

Note: the RADCombo.ClearSelection() function does not fix the problem.

Help greatly appreciated.
Thanks

3 Answers, 1 is accepted

Sort by
0
Rosi
Telerik team
answered on 27 Oct 2008, 01:25 PM
Hi Paul,

If you set an unexisted value to the SelectedValue an "selection out of range"  error should appears. In that case you can use try-catch block to catch the exception and implement your custom logic.

For example:
try
{
    cmbNames.SelectedValue = "Johnson";
}
catch (Exception e)
{

  
}

OR you can check does this value exist before selecting it and throw your custom error:

if( cmbNames.FindItemByValue("Johnson") == null )
{
  //throe your error.
}

Kind regards,
Rosi
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Paul
Top achievements
Rank 1
answered on 29 Oct 2008, 12:27 PM
we already tested the FindControl method you suggested and it works fine. However we are interested in why when assigned the combo box to a non-existing value it only throws an error in some occassions whilst in others it assigns the combo to selected index 0.

Help appreciated.
0
Rosi
Telerik team
answered on 29 Oct 2008, 01:24 PM
Hi Paul,

Selecting an existing value will throw an error if you call the DataBind() method of RadComboBox.
In other case it will just not select anything.

This behavior is by design. You can see that the  standard ASP.NET DropDownList behaves by the same way.

Regards,
Rosi
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
ComboBox
Asked by
Paul
Top achievements
Rank 1
Answers by
Rosi
Telerik team
Paul
Top achievements
Rank 1
Share this question
or