Excel VBA TreeView 链接到 ComboBox

Excel VBA TreeView linking to ComboBox

我有一个用户窗体,其中有一个 TreeView 和一个 ComboBox:

Private Sub UserForm_Initialize()

With TreeView1.Nodes
.Add , , "A", "Item1"
    .Add "A", tvwChild, , "SubItem1"

.Add , , "B", "Item2"
    .Add "B", tvwChild, , "SubItem2"
End With 

With ComboBox1
.AddItem "Case1"
.AddItem "Case2"
.AddItem "Case3"
.AddItem "Case4"
End With 

End Sub

我现在的目标是,当我 select TreeView 中的父节点时,只有 ComboBox 中的某些项目显示给我。例如:我 select Item2 并且在 ComboBox 中案例 1 和案例 3 只显示给我。我尝试做一个 If 循环,但没有成功。

我怎样才能真正做到这一点,这可能吗?

TreeView1_NodeClick 事件 returns Node 被点击。使用 Node.Text 值确定将哪些项目添加到 ComboBox

Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
    With ComboBox1
        .Clear
        Select Case Node.Text
            Case "A"
                .AddItem "Case1"
                .AddItem "Case3"
            Case "B"
                .AddItem "Case2"
                .AddItem "Case4"
        End Select
    End With
End Sub

附录

OP 指出他需要在他的用例中使用 Node.Key 属性。

Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
    With ComboBox1
        .Clear
        Select Case Node.Key
            Case "A"
                .AddItem "Case1"
                .AddItem "Case3"
            Case "B"
                .AddItem "Case2"
                .AddItem "Case4"
        End Select
    End With
End Sub