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

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

1 Answer 36 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Tomica
Top achievements
Rank 2
Tomica asked on 16 Oct 2012, 09:47 PM
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?

 

1 Answer, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 19 Oct 2012, 03:02 PM
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.
Tags
ComboBox
Asked by
Tomica
Top achievements
Rank 2
Answers by
Nencho
Telerik team
Share this question
or