2011-12-12 67 views
0

由于标题暗示我有兴趣从4个组合框中获取值。所有4个组合框在列出0-9的数字时都是相同的。我想将这些数字分配给一个字符串变量。例如,如果用户选择(CB1 = 4)(CB2 = 3)(CB3 = 2)(CB4 = 1)我想采取这些选择并将它们分配给一个字符串变量。提前致谢。如何从多个组合框中获取值

-Nogard

+1

这是使用的WinForms或WPF? – eandersson

+0

您是否正在寻找一种有效的方法?或者,每个组合框的'.SelectedItem'属性有什么问题,并附加到一个字符串? –

回答

1

如果你正在使用的WinForms

string s""; 

    private void combobox1_SelectedIndexChanged(object sender, EventArgs e) 
     { 
      s = combobox1.Text+ combobox2.Text+ combobox3.Text+ combobox4.Text; 
     } 

    private void combobox2_SelectedIndexChanged(object sender, EventArgs e) 
     { 
      s = combobox1.Text+ combobox2.Text+ combobox3.Text+ combobox4.Text; 
     } 
    private void combobox3_SelectedIndexChanged(object sender, EventArgs e) 
     { 
      s = combobox1.Text+ combobox2.Text+ combobox3.Text+ combobox4.Text; 
     } 
    private void combobox4_SelectedIndexChanged(object sender, EventArgs e) 
     { 
      s = combobox1.Text+ combobox2.Text+ combobox3.Text+ combobox4.Text; 
     } 

或致电只有在所有组合框选定的指数变化的事件,因为所有的都在做同样的

+0

我肯定会创建并使用一个函数来完成字符串连接。 –

+0

比我想像的要容易得多。 –

+0

如果有用,请将其标记为答案 – Nighil