Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set Combobox System.ArgumentOutOfRangeException

Status
Not open for further replies.

rwttm001

IS-IT--Management
Nov 20, 2002
26
GB
Hi

This is driving me crazy - I have a DataBound combobox populated as follows:

cmbWeather.DataSource = MyDataObject.PopulateWeather 'databind to datatable
cmbWeather.ValueMember = "ID"
cmbWeather.DisplayMember = "Value"

Using the value of the combobox I populate the ID value into SQL Server no problem, but when I come to retrieve the record and set the combobox accordingly I get the System.ArgumentOutOfRangeException , as if the value I'm trying to set to isn't there, when I know that it is.

Here's the code to set the combobox value (the sub is to handle SQL nulls):

FormatCombo(dsCall.Tables("tblCall").Rows(0), cmbWeather, "intWeatherID")
>>>>>
Private Sub FormatCombo(ByVal MyDataRow As DataRow, ByVal MyComboBox As ComboBox, ByVal MyColumnName As String)
If MyDataRow.Item(MyColumnName) Is System.DBNull.Value Then
MyComboBox.SelectedIndex = 0
Else
MyComboBox.SelectedValue = MyDataRow.Item(MyColumnName)
End If
End Sub

This sub works fine for a number of other comboboxes in the project, does anyone know whats going on? I even tried deleting and recreatinf the control but no joy....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top