0

私のコードをテストしている間。私の編集ウィンドウフォームでは、コンストラクターが下に存在します

public Edit(List<Item> i, int index)
{
    itemListBox.SetSelected(index, true);
    itemList = i;
    InitializeComponent();
}

編集ウィンドウが開きます

var editor = new Edit(itemList, itemListBox.SelectedIndex);
editor.Show();

残念ながら私は得る

Object reference not set to an instance of an object.

私がやろうとしているのは、リストボックスのあるメインウィンドウがあり、アイテムをダブルクリックすると、リストボックスと同じアイテムで新しいフォームが開きます。メインウィンドウでダブルクリックしたアイテムを、ポップアップする編集ウィンドウで選択したアイテムにしたいです。

4

1 に答える 1

1

最初に入れInitializeComponent()てから、コードを適用します。

public Edit(List<Item> i, int index)
{
    InitializeComponent();
    itemListBox.SetSelected(index, true);
    itemList = i;
}

itemListBoxInitializeComponent()メソッド内で宣言および初期化されます。

于 2013-09-10T08:58:59.690 に答える