none
vb 2008 控制項陣列Combobox 一個有跳到要執行的event 另一個則沒有,這是為什麼呢? RRS feed

  • 問題

  • 這邊有一個 combox1是從控制項拉到VB的form 

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

            For j = 1 To 8
                Dim nowWaveComboBox As ComboBox = CType(Me.Controls("WaveSelectCombox" & j), ComboBox)
                Dim nowRepeatComboBox As ComboBox = CType(Me.Controls("RepeatCombox" & j), ComboBox)
                Dim nowWaveList As New List(Of String)
                Dim nowRepeatList As New List(Of Integer)

                'nowWaveList.Add("")

                For i = 1 To 255
                    nowWaveList.Add(WavShortPath(i))
                    nowRepeatList.Add(i)
                Next
                nowWaveComboBox.DataSource = nowWaveList           '
                nowRepeatComboBox.DataSource = nowRepeatList      '斷點 一  沒有跳到event裡WaveSelectCombox_SelectedIndexChanged

                nowRepeatComboBox.SelectedIndex = 0                    '斷點二   有跳過去RepeatCombox_SelectedIndexChanged

            Next

              End Sub

     Private Sub CreateWaveSelectCombox()
            Dim textname As String

            Dim i As Integer
            For i = 1 To 8
                textname = "WaveSelectCombox" + CStr(i)
                Dim WaveSelectCombox As New ComboBox
                WaveSelectCombox.Size = New Size(150, 20)

                WaveSelectCombox.Name = textname
                WaveSelectCombox.Items.Add("")

                WaveSelectCombox.DropDownStyle = ComboBoxStyle.DropDownList
                WaveSelectCombox.BackColor = Color.BlanchedAlmond
                WaveSelectCombox.Location = (New Point(60, 90 + i * 27))

                Me.Controls.Add(WaveSelectCombox)

                CType(Me.Controls("WaveSelectCombox" & i), ComboBox).SelectedIndex = 0

                AddHandler WaveSelectCombox.SelectedIndexChanged, AddressOf WaveSelectCombox_SelectedIndexChanged
            Next

        End Sub

     

        Private Sub CreateRepeatCombox()
            Dim textname As String
            Dim i As Integer


            For i = 1 To 8
                textname = "RepeatCombox" + CStr(i)
                Dim RepeatCombox As New ComboBox
                RepeatCombox.Size = New Size(40, 20)

                RepeatCombox.Name = textname
                RepeatCombox.Items.Add("")

                RepeatCombox.DropDownStyle = ComboBoxStyle.DropDownList
                RepeatCombox.BackColor = Color.BlanchedAlmond
                RepeatCombox.Location = (New Point(240, 90 + i * 27))


                Me.Controls.Add(RepeatCombox)
                CType(Me.Controls("RepeatCombox" & i), ComboBox).SelectedIndex = 0

                AddHandler RepeatCombox.SelectedIndexChanged, AddressOf RepeatCombox_SelectedIndexChanged
            Next


        End Sub

     


        Private Sub RepeatCombox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Dim O As Object = CType(sender, ComboBox)
            Dim i As Integer = CInt(O.name.Replace("RepeatCombox", ""))

            If CanChangeSelectIndex = False Then
                Exit Sub
            End If

            If ComboBox1.SelectedIndex < 0 Then
                Exit Sub
            End If
            Select Case i
                Case 1 To 8

                    TemplateRepeatTimeIndex(ComboBox1.SelectedIndex, i) = CType(Me.Controls(O.name), ComboBox).SelectedIndex
            End Select
        End Sub

        Private Sub WaveSelectCombox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Dim O As Object = CType(sender, ComboBox)
            Dim i As Integer = CInt(O.name.Replace("WaveSelectCombox", ""))
            If CanChangeSelectIndex = False Then
                Exit Sub
            End If
                Select i
                Case 1 To 8
                    TemplateFileStringIndex(ComboBox1.SelectedIndex, i) = CType(Me.Controls(O.name), ComboBox).SelectedIndex
            End Select

        End Sub


      Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
            Dim i As Integer
            TextBox1.Text = "Template" & ComboBox1.SelectedItem


            CanChangeSelectIndex = False
            For i = 1 To 8
                Dim cbxWave As ComboBox = DirectCast(Me.Controls("WaveSelectCombox" & i), ComboBox)
                Dim cbxRepeat As ComboBox = DirectCast(Me.Controls("RepeatCombox" & i), ComboBox)

                cbxWave.SelectedIndex = TemplateFileStringIndex(ComboBox1.SelectedIndex, i)
                cbxRepeat.SelectedIndex = TemplateRepeatTimeIndex(ComboBox1.SelectedIndex, i)
            Next
            CanChangeSelectIndex = True


        End Sub

    2009年8月5日 上午 09:08

解答

所有回覆