InvalidArgument =' 0'的值对于' SelectedIndex'无效。参数名称:SelectedIndex组合框VS 2008

时间:2017-06-21 06:28:56

标签: vb.net visual-studio-2008 combobox

我收到此错误: InvalidArgument =' 0'的值对于' SelectedIndex'无效。参数名称:SelectedIndex 在我的代码的这一部分:

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    con.Open()
    ds = New DataSet
    tables = ds.Tables
    da = New OleDbDataAdapter("Select * from [Questions]", con)
    da.Fill(ds, "Questions")
    Dim view1 As New DataView(tables(0))
    With ComboBox1
        .DataSource = ds.Tables("Questions")
        .ValueMember = "ID"
        .DisplayMember = "ID"
        .SelectedIndex = 0
    End With
    con.Close()
    ComboBox1.SelectedIndex = NumericUpDown1.Value
    NumericUpDown1.Value = ComboBox1.SelectedIndex
    NumericUpDown1.Maximum = ComboBox1.Items.Count - 1
End Sub

以上代码适用于我朋友的VS 2010,但是当我将完全相同的代码传输到VS 2008时,它就把这个错误抛给了我。我尝试插入if else语句如果ComboBox1.Items.Count> 0但它仍然无法正常工作。有什么想法吗?

0 个答案:

没有答案