I have 8 combobox on my form.
I have to set for each of them the selected value (Radcombo.Selectedvalue="Text")
In some case the value does not exist in the combobox, so I need to set the combo.selectedvalue to nothing
Do do this I use a "Try-Catch as Exception" for each combo ! As you know Try-Catch is not good for performances.
Here my code
Try
Zlocaledit.SelectedValue = Zlocal.Text
Catch ex As Exception
Zlocaledit.SelectedIndex = Nothing
End Try
Try
ZServiceEdit.SelectedValue = Zservice.Text
Catch ex As Exception
ZServiceEdit.SelectedIndex = Nothing
End Try
Try
ZSocedit.SelectedValue = ZSoc.Text
Catch ex As Exception
ZSocedit.SelectedIndex = Nothing
End Try
Etc etc etc
Is there another way to do this ? (Without a Try-Catch)
Thanks all
6 Answers, 1 is accepted
There is no need to use try-catch-block.
If the value that you set does not exist the SelectedIndex of the RadComboBox will be set automatically to 0(or -1 if the AllowCustomText property of RadCombobox is enabled)
Note that the SelectedIndex property cannot be set to Nothning.Its default value is 0 for readonly mode and -1 when AllowCustomText property is set to true.
Regards,
Rosi
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

Thanks

Here's the code i use:
cboUNUMBER.SelectedValue = .UNUMBER
Any ideas why this is happening ? i can fix the problem but need to know why its throwing an error in one instance and not another
Is the ComboBox data bound in the cases the error appears? If this is true, try calling cboUNUMBER.ClearSlection() before setting the selected value in these cases.
Best wishes,
Simon
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

Hi,
The combo box is bound in both instances where the error occurs and does not occur. That did not appear to fix the problem, however we do already have a solution to the problem as follows:
If cboUNUMBER.FindItemByValue(.UNUMBER) Is Nothing Then
cboUNUMBER.SelectedIndex = 0
Else
cboUNUMBER.SelectedValue = .UNUMBER
cboUNUMBER.FindItemByValue(.UNUMBER).Selected = True
End If
We are more interested in why such an error would occur in the first place and if it can be resolved by a simplier measure so we know how to identify such an error in the future and the best way to solve the problem.
Generally, this error appears if there is a selected Item in the ComboBox and then the ComboBox is bound to a data source which does not contain the selected Item.
In your case, the cause of the error may be different but without looking at your code I will be unable to pinpoint it.
Please open a formal support ticket and send us the page there for additional inspection.
Best wishes,
Simon
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.