2014-09-21 41 views
0

我有我的窗體2個組合框,如果組合框1國家「德國家庭購物」,如果給出了以下陣列如果組合框是那麼數組值填充替代組合框VB​​A

If ComboBox1.Value = "Germany Home Shopping" Then 
ComboBox2.List = Array("GER Singles ABE", "GER Singles CDF", "GER Small Cat ABE", "GER Small Cat CDF", "GER Small Cat All Zone", "GER Large Cat ABE", "GER Large Cat CDF", "GER Large Cat All Zone") 
End If 

我也想這樣做相反,如果值是組合框2中的數組答案之一,那麼它將把德國家庭購物放在組合框1中。我認爲這可以這樣做?

If ComboBox2.List = Array("GER Singles ABE", "GER Singles CDF", "GER Small Cat ABE", "GER Small Cat CDF", "GER Small Cat All Zone", "GER Large Cat ABE", "GER Large Cat CDF", "GER Large Cat All Zone") Then 
ComboBox1.Value = "Germany Home Shopping" 
End If 

但這似乎並沒有爲我工作。

在此先感謝:-) 鋁

+0

變化,如果你通過像'陣列測試語句循環在陣列中的每個ELE(X,Y,Z ):if combobox2.selecteditem = ele then:combobox1.value =「Germany etc ..」:exit for:end if:Next' – 2014-09-21 19:07:17

+0

@Cor_Blimey我收到一個編譯錯誤,指出找不到方法或數據成員? – 2014-09-21 19:16:04

回答

1

你可以試試這個:

Dim mylist 
mylist = Array("GER Singles ABE", "GER Singles CDF", "GER Small Cat ABE", _ 
     "GER Small Cat CDF", "GER Small Cat All Zone", "GER Large Cat ABE", _ 
     "GER Large Cat CDF", "GER Large Cat All Zone") 
If Not IsError(Application.Match(Me.ComboBox2.Value, mylist, 0)) Then 
    Me.ComboBox1.Value = "Germany Home Shopping" 
End If 
+0

這會將combobox1更新到相關通道,然後它將combobox2變回空白。 – 2014-09-22 10:04:57

+0

@AlanTreanor其實我很想知道你爲什麼要這樣做。如果你在** ComboBox1 **中有一個* Change_Event *來填充** ComboBox2 ** List,它不會特別加起來。所以基本上它是** ComboBox2 **列表是基於** ComboBox1 **或反之亦然。 – L42 2014-09-22 21:40:45