How do I deal with a "selection out of range" error

2 posts, 0 answers
  1. Tomica
    Tomica avatar
    147 posts
    Member since:
    Apr 2008

    Posted 16 Oct 2012 Link to this post

    A very simple use of RAD combo:

    Datasource provides a list of values to load the combo box. Plain-vanilla VB.Net code.

    This combo box is used in an edit form, and the selected value is set when the record to be edited is read from the SQL Server database.

    We are not using any type of binding.

    So, when I attempt to initialize the combo when the page loads, I find that I have a value in the database that triggers an error that is not trapped by a traditional Try / Catch construct. (see attachment)

    In this particular example, the code found in the database did not match any value in the datasource for this combo and I get a hard, untrapped error on the selected value assignment. ("selection out of range")

    I am hoping that I am doing something really stupid and overlooking an obvious solution, anybody care to show me my error?

     

        type_code = reader("type_code").ToString
    Try
        Me.Type_Code_Combo.SelectedValue = type_code
    Catch ex As Exception
        ' just ignore if there is no match
    End Try

     

     Note: I am aware that I can set "allow custom text" but that is not the intent, rather to insulate my page from data errors, and allow for corrections by setting the selected value to nothing and letting the user make a proper selection. But if that is the only way, how to I synchronize so that the text in the box matches the selectedvalue in the list?

     

  2. Nencho
    Admin
    Nencho avatar
    1457 posts

    Posted 19 Oct 2012 Link to this post

    Hello Thomas,

    We are unable to determine what might cause the problem from the provided snippet of code and explanations. For that matter, could you open a support ticket, along with a runnable sample, demonstrating the problematic behavior? Thus we could inspect the problem locally and provide you a suitable solution.

    Regards,
    Nencho
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top