在VB中更新动态生成的控件上的文本

时间:2019-06-20 21:00:51

标签: vb.net

我有一个动态生成的TabControl,并且正在尝试更新TabPage中的组合框。更新组合框的功能称为click事件。

我尝试通过将动态生成的控件作为属性存储在类How to pass value from one form to another form's dynamically created control

上来遵循有关操纵动态生成的控件的一些指南。

控件是这样动态生成的:

    Public Class Form1
           Public Sub loadForm()
           Dim ctp As New CustomTabPage("Tab number" & i, ErrorList(i), myList, New Object)
           Me.myTabControl.TabPages.Add(ctp)
            ...
           End Sub
        End Class

        Public Class CustomTabPage
            Inherits TabPage
            Private m_testSelect As ComboBox
            ...
            Public Property testSelect() As ComboBox
               Get
                   testSelect = m_testSelect
               End Get
               Set(ByVal mytestSelect As ComboBox)
                   m_testSelect = mytestSelect
               End Set
            End Property

            Public Sub newTab()
            m_testSelect = New ComboBox    
            With m_testSelect
                    .Location = New System.Drawing.Point(locX + labelSize, locY)
            End With
            Me.Controls.Add(m_testSelect)

            Dim ccb As New CustomCheckBox()
            Me.Controls.Add(m_testSelect)
            End Sub
            Public Sub UpdateCBOs(ByVal i As Integer)
                If i = 1 Then
                    testSelect.Text = "Test1"
                ElseIf i = 0 Then
                    testSelect.Text = "Test2"
                End If
                ... 
            End Sub
        End Class

        Public Class CustomCheckBox
               Inherits CheckBox
               Public Sub Clicked(sender As Object, e As EventArgs) Handles MyBase.CheckedChanged
                    Dim ctp = CType(Form1.myTabControl.SelectedTab, CustomTabPage)
                    ctp.UpdateCBOs(i)
                End Sub
         End Class

当前通过调试时,我在下一行停止         errorBy.Text =“ Test1”

当我将鼠标悬停在errorBy.Text上,并看到该errorBy.Text =“”时,实际上在单击事件完成后,我在窗体上看到该组合框未更新。

0 个答案:

没有答案