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

Set selected value of a lot of combo

6 Answers 169 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Filleau
Top achievements
Rank 1
Filleau asked on 16 Sep 2008, 01:38 PM
Hi

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

Sort by
0
Accepted
Rosi
Telerik team
answered on 18 Sep 2008, 06:51 AM
Hello Filleau,

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.
0
Filleau
Top achievements
Rank 1
answered on 19 Sep 2008, 12:02 PM
Tested and approved !
Thanks
0
Paul
Top achievements
Rank 1
answered on 24 Oct 2008, 03:15 PM
i am having a problem with setting the value of the radcombobox, not too dissimilar to this problem. On page load when i assign the combo box to a value which doesnt exist in the combo box it doesnt throw any errors, although when i used the same code to assign the combo box to the same value elsewhere its does throw an error stating that the 'Specified argument was out of the range of values'.

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

0
Simon
Telerik team
answered on 24 Oct 2008, 03:31 PM
Hello Paul,

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.
0
Paul
Top achievements
Rank 1
answered on 24 Oct 2008, 03:50 PM

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.

 

 

0
Simon
Telerik team
answered on 27 Oct 2008, 03:12 PM
Hello Paul,

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.
Tags
ComboBox
Asked by
Filleau
Top achievements
Rank 1
Answers by
Rosi
Telerik team
Filleau
Top achievements
Rank 1
Paul
Top achievements
Rank 1
Simon
Telerik team
Share this question
or