如何从多个组合框中获取值

时间:2011-12-12 07:31:39

标签: c#

标题显示我有兴趣从4个组合框中获取值。所有4个组合框都是相同的,它们列出了0-9的数字。我想取这些数字并将它们分配给单个字符串变量。因此,例如,如果用户选择(CB1 = 4)(CB2 = 3)(CB3 = 2)(CB4 = 1),我想采取这些选择并将它们分配给字符串变量。在此先感谢。

-Nogard

1 个答案:

答案 0 :(得分: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;
        }

或仅在所有组合框中调用选定的索引更改事件,因为所有组件都在相同