Specified argument was out of the range of valid values.

Hi
   I am getting a error "Specified argument was out of the range of valid values. Parameter name: '-2147483648' is not a valid value for 'index'." When I was trying to set selected value property value for the combo box.
I have given the code for your reference.

With cboName
     .DataSource = dtSource
     .DisplayMember = strDisplayMember
     .ValueMember = strValueMember
End With
cboName.SelectedValue = intCalibrateId.ToString

After binding the combo box member, I am setting the value to the selectedValue property.
Please findout where I have done a mistake and how to rectify this.


Thanks in advance
M. Rabeek Ahamed



Answer this question

Specified argument was out of the range of valid values.

  • BobRS

    Hello Rabeek
      Code looks OK to me . Can you just make sure you are setting the Datasource property property (Like Dataset11.TableName) . I also tried out a similar scenario and it worked .  When you set the Selected Value , you should use an existing  column value from the Value member property
    For eg if you take Categories Table from Northwind
        .ValueMember = CategoryID
    .SelectedValue should be an existing column value from categoryID Column .

     If these dont help , Can you send me the schema of the table and exact code

    Thanks
    Sunder
    VB.Net team 

  • Troy Gerton

    Thanks sundar.

            I found the problem why it was happened. This problem occurs because of the below mistake which i have made at the time of designing.
       "Copy and paste the Combo box which is available already in the form."

       My value member contains the value which is assigned by me. Everything is perfect in my part. When I set the value member as other than the second item in the combo list, It is working fine. When I set the second Item as value member in the combo list then I face this issue.

       The below code will work fine even we copy and paste the combo box at the time of designing.

    Private Sub SetComboSelectedValue(ByRef objCombo As ComboBox, ByVal strColName As String, ByVal strSelectedValue As String)

    For Each item As Object In objCombo.Items

    If CType(item, DataRowView)(strColName).ToString() = strSelectedValue Then

    objCombo.SelectedItem = item

    Exit For

    End If

    Next

    End Sub


    Thanks And Regards,
    M. Rabeek Ahamed
    Satyam Computer services Ltd.
    Chennai
    India


  • Specified argument was out of the range of valid values.