0

テキストボックスと対応するコンボボックスをコンボボックスの変更イベントとともに動的に作成するフォームを作成しました。これは、コンボボックスイベントハンドラーを作成するクラスです

Option Explicit

Public WithEvents cbx As MSforms.Combobox
Private avarSplit As Variant

Sub SetCombobox(ctl As MSforms.Combobox)
  Set cbx = ctl
End Sub

Private Sub cbx_Change()
 Dim i As Integer
  If cbx.ListIndex > -1 Then
  'MsgBox "You clicked on " & cbx.Name & vbLf & "The value is " & cbx.Value
  avarSplit = Split(cbx.Name, "_")
    'DecessionOnValue
 End If
End Sub

そして、テキストボックスとコンボボックスを動的に作成しているフォームのコードは次のとおりです

Function AddTextBox(Frame1 As frame, numberOfColumns As Integer)

 Dim counter As Integer
 Dim i As Integer
 Dim TxtBox As MSforms.TextBox
 For counter = 1 To numberOfColumns
                                     'Forms.CommandButton.1
    Set TxtBox = Frame1.Controls.Add("Forms.TextBox.1")
    TxtBox.Name = "tb_" + CStr(counter)
    'Bouton.Caption = "Test"
    TxtBox.Visible = True
    i = Property.TextBoxDisable(TxtBox)
    ' Defining coordinates  TextBox height is 18
    If counter = 1 Then
        TxtBox.Top = 23
    Else
        TxtBox.Top = (18 * counter) + 5 * counter
    End If
        TxtBox.Left = 50
   Next counter
End Function

Function Combobox(Frame1 As frame, numberOfColumns As Integer)

Dim counter As Integer
Dim i As Integer
Dim CbBox As MSforms.Combobox
Dim cbx As ComboWithEvent

If pComboboxes Is Nothing Then Set pComboboxes = New Collection
   For counter = 1 To numberOfColumns
                                     'Forms.CommandButton.1
    Set CbBox = Frame1.Controls.Add("Forms.ComboBox.1")
    CbBox.Name = "cb_" + CStr(counter)
    i = AddComboboxValues(CbBox)
  ' Defining coordinates  TextBox height is 18
    If counter = 1 Then
        CbBox.Top = 23
    Else
        CbBox.Top = (18 * counter) + 5 * counter
    End If
        CbBox.Left = 150
        Set cbx = New ComboWithEvent
        cbx.SetCombobox CbBox
        pComboboxes.Add cbx
    Next counter
    i = AddScrollBar(Frame1, counter)

End Function

コンボボックス イベント ハンドラーは正常に動作していますが、動的コンボ ボックスで選択された値に応じて、テキスト ボックスのテキストをコピーしたり、テキスト ボックスを無効にしたりする方法がわからないという問題があります。

ありがとう、ジャティン

4

1 に答える 1

0

たとえば、これを使用します。

Me.Controls("ControlName").Visible = True または、Visible の代わりに enable、disable などを使用できます。

于 2013-11-21T14:36:51.143 に答える