none
vb 2008 combobox為什麼沒有更新呢? RRS feed

  • 問題

  • 請教各位大哥大姐,我在斷點都看到 a(0)被取代成100了 ,為什麼我的combobox還是0-6呢??
    Public Class Form1

        Dim a As List(Of Integer) = New List(Of Integer)

     

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        End Sub

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim i As Integer
            For i = 0 To 6
                a.Add(i)
            Next
            ComboBox1.DataSource = a
        End Sub

        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            a.Item(0) = 100
            ComboBox1.DataSource = a
        End Sub
    End Class

    2009年8月25日 下午 02:32

解答

  • Public Class Form1
        Dim a As List(Of Integer) = New List(Of Integer)
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim i As Integer
            For i = 0 To 6
                a.Add(i)
            Next
            ComboBox1.DataSource = Nothing
            ComboBox1.DataSource = a
        End Sub

        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            a.Item(0) = 100
            ComboBox1.DataSource = Nothing
            ComboBox1.DataSource = a
        End Sub
    End Class


    .NET菜鳥自救會 http://www.dotblogs.com.tw/chou/
    2009年8月25日 下午 02:46
    版主

所有回覆

  • Public Class Form1
        Dim a As List(Of Integer) = New List(Of Integer)
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim i As Integer
            For i = 0 To 6
                a.Add(i)
            Next
            ComboBox1.DataSource = Nothing
            ComboBox1.DataSource = a
        End Sub

        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            a.Item(0) = 100
            ComboBox1.DataSource = Nothing
            ComboBox1.DataSource = a
        End Sub
    End Class


    .NET菜鳥自救會 http://www.dotblogs.com.tw/chou/
    2009年8月25日 下午 02:46
    版主
  • 感謝小毆哥指導
    請問小毆哥,為什麼要加入這一行呢?
     ComboBox1.DataSource = Nothing
    是要先把它清空才可以這樣嗎?沒清空就不可以,我這樣理解對嗎?

    2009年8月25日 下午 02:53