none
Specified argument was out of the range of valid values.Parameter name: '0'is not a valid value for 'index'

    Question

  • I have made my ListBox and ComboBox control which are derived form System.Windows.Forms.ListBox and System.Windows.Forms.ComboBox respectively.

    When I am populating these controls initially it was throwing error:
    "Could Not Bind to the New display member. Parameter Name: newDisplayMember"

    After doing some changes in the ValueMember property, now it is throwing an error:
    "Specified argument was out of the range of valid values.Parameter name: '0'is not a valid value for 'index'"

    The code is here:



    ComboBox1.DataSource = objDS.Tables(0)
    ComboBox1.DisplayMember = "XYZ_DSCR"
    ComboBox1.ValueMember = "XYZ_ID"

     

    I have checked the same code for normal combobox,it is working. But for my combobox which is derived from the ComboBox ,it is throwing above exception.
    ObjDS contains valid vlaues for both the Columns ...

    Please help me out..I am struggling since many hours...

    --- DotNetParam

    Tuesday, October 25, 2005 6:17 AM

Answers

  • I don't know why but binding combobox with the object collection of custom class
    having two properties - DisplayMember and ValueMember worked !!!

    I have to loop through every row of datatable and create new object and then add the object like


    For Each row As DataRow In dataTable.Rows

    Me.Items.Insert(i, New ComboBoxData(Trim(row.Item(DisplayMember)), row.Item(ValueMember)))
    i = i + 1

    Next row


     



    Where DisplayMember and ValueMember are string constants...

    I am very much surprised why this worked and not the original
    Combo1.DataSource =...
    Combo1.DisplayMember = ..
    Combo1.ValueMember = ..

    Friday, October 28, 2005 6:17 PM

All replies

  • Here is the stacktrace:
    Exception Message:
    Specified argument was out of the range of valid values.
    Parameter name: '0' is not a valid value for 'index'.

    stackTrace:   at System.Windows.Forms.ComboBox.set_SelectedIndex(Int32 value)
       at System.Windows.Forms.ListControl.DataManager_ItemChanged(Object sender, ItemChangedEventArgs e)
       at System.Windows.Forms.ListControl.SetDataConnection(Object newDataSource, BindingMemberInfo newDisplayMember, Boolean force)
       at System.Windows.Forms.ListControl.set_ValueMember(String value)
       at BindDataToComboBox(DataSet data, ComboBox& cboBox1, String DisplayMember, String ValueMember, Object SelectedValue) in D:\Project1\BaseUserControl.vb:line 1191
       at DataBindUC.DataBindUC_Load(Object sender, EventArgs e) in  D:\Project2\DataBindUC.vb:line 116
    Wednesday, October 26, 2005 4:23 AM
  • I don't know why but binding combobox with the object collection of custom class
    having two properties - DisplayMember and ValueMember worked !!!

    I have to loop through every row of datatable and create new object and then add the object like


    For Each row As DataRow In dataTable.Rows

    Me.Items.Insert(i, New ComboBoxData(Trim(row.Item(DisplayMember)), row.Item(ValueMember)))
    i = i + 1

    Next row


     



    Where DisplayMember and ValueMember are string constants...

    I am very much surprised why this worked and not the original
    Combo1.DataSource =...
    Combo1.DisplayMember = ..
    Combo1.ValueMember = ..

    Friday, October 28, 2005 6:16 PM
  • I don't know why but binding combobox with the object collection of custom class
    having two properties - DisplayMember and ValueMember worked !!!

    I have to loop through every row of datatable and create new object and then add the object like


    For Each row As DataRow In dataTable.Rows

    Me.Items.Insert(i, New ComboBoxData(Trim(row.Item(DisplayMember)), row.Item(ValueMember)))
    i = i + 1

    Next row


     



    Where DisplayMember and ValueMember are string constants...

    I am very much surprised why this worked and not the original
    Combo1.DataSource =...
    Combo1.DisplayMember = ..
    Combo1.ValueMember = ..

    Friday, October 28, 2005 6:17 PM