前のリストボックスでアイテムがクリックされた後にのみ表示される複数のリストボックスを作成したいとします。リストボックス1のアイテムを選択すると、リストボックス2のアイテムが表示されます。リストボックス2のアイテムをクリックすると、リストボックス3のすべてのアイテムが表示されます。リストボックス1のアイテムをクリックしてリストボックス2を表示しますしかしその後、次のエラーが発生します。オブジェクト参照がオブジェクトのインスタンスに設定されていない。複数のリストボックスを表示するにはどうしたらいいですか?現在選択されていないリストボックスのマウスクリックを設定する方法は?
private void Form1_Load(object sender, EventArgs e)
{
listBox1.Items.Add(1);
listBox1.Items.Add(2);
listBox1.Items.Add(3);
}
private void Form1_MouseClick(object sender, MouseEventArgs e)
{
string curItem1 = listBox1.SelectedItem.ToString();
if (curItem1 == "1")
{
listBox2.Items.Add(1);
if(curItem1 == "1")
{
listBox3.Items.Add(1);
}
string curItem2 = listBox2.SelectedItem.ToString();
///This is where I get the error!
}
}