ありがとう、SelectionChangeCommittedのように。イベントハンドラは、特定の条件が満たされたときに自動的にメソッドを呼び出すために使用されるため、ループでポーリングすることなく特定の条件付きアクションを実行できます。ここでは、あなたが探しているものを行うべきである例がありますが、ユーザーフレンドリーではないユーザーにとってはそうです。あなただけのコンボボックスの初期状態を設定する必要が続いて
// List the combo boxes in the order you want them to enable.
ComboBox[] _boxes = { comboBox1, comboBox2, comboBox3 };
private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
int index = Array.IndexOf(_boxes, (ComboBox)sender);
// Disable the combo box that just got its value selected.
_boxes[index].Enabled = false;
// If it's not the last combo box in the array, enable the next one.
if(index < _boxes.Length - 1)
_boxes[index + 1].Enabled = true;
}
:
public partial class ExampleForm : Form
{
public ExampleForm()
{
InitializeComponent();
comboBox1.Enabled = true;
comboBox2.Enabled = false;
comboBox3.Enabled = false;
comboBox1.Items.Add("option1");
comboBox1.Items.Add("option2");
comboBox2.Items.Add("option1");
comboBox2.Items.Add("option2");
comboBox3.Items.Add("option1");
comboBox3.Items.Add("option2");
comboBox1.OnSelectedIndexChanged += comboBox1_OnSelectedIndexChanged;
comboBox2.OnSelectedIndexChanged += comboBox2_OnSelectedIndexChanged;
comboBox3.OnSelectedIndexChanged += comboBox3_OnSelectedIndexChanged;
}
void comboBox1_OnSelectedIndexChanged(object sender, EventArgs e)
{
comboBox1.Enabled = false;
comboBox2.Enabled = true;
}
void comboBox2_OnSelectedIndexChanged(object sender, EventArgs e)
{
comboBox2.Enabled = false;
comboBox3.Enabled = true;
}
void comboBox3_OnSelectedIndexChanged(object sender, EventArgs e)
{
comboBox1.Enabled = true;
comboBox3.Enabled = false;
}
}
これはWinFormsアプリケーションですか? – itsme86
質問にあなたのコードを追加してください。 – Kinetic
はいWindowsフォーム。 – Thomas