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....
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....