Set selected value of a lot of combo

7 posts, 1 answers
  1. Filleau
    Filleau avatar
    114 posts
    Member since:
    Jun 2006

    Posted 16 Sep 2008 Link to this post

    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

  2. Answer
    Rosi
    Admin
    Rosi avatar
    2527 posts

    Posted 18 Sep 2008 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Filleau
    Filleau avatar
    114 posts
    Member since:
    Jun 2006

    Posted 19 Sep 2008 Link to this post

    Tested and approved !
    Thanks
  5. Paul
    Paul avatar
    38 posts
    Member since:
    Oct 2008

    Posted 24 Oct 2008 Link to this post

    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

  6. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 24 Oct 2008 Link to this post

    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.
  7. Paul
    Paul avatar
    38 posts
    Member since:
    Oct 2008

    Posted 24 Oct 2008 Link to this post

    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.

     

     

  8. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 27 Oct 2008 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017