我正在尝试将selectedItem从ListBox in Form2中取出,并将其放到Form1中的TextBox中,但我的错误是
对象引用未设置为对象的实例
我知道空对象是什么,我知道它在做什么,什么时候做,但是我找不到我的错误。
我在Form2中的代码,其中有我的ListBox
private Form1 mainForm = null;
public Form2(Form1 callingFrom)
{
mainForm = callingFrom as Form1;
InitializeComponent();
}
private void okButton_Click(object sender, EventArgs e)
{
this.mainForm.udaje = bankovniUctyList.GetItemText(bankovniUctyList.SelectedItem);
this.Close();
}我在Form1中的代码,其中有我的TextBox
public string udaje
{
get { return predmetBanka.Text; }
set { predmetBanka.Text = value; bankaTextBox.Text = predmetBanka.Text; }
}调试器说,这个问题在这里。
this.mainForm.udaje = bankovniUctyList.GetItemText(bankovniUctyList.SelectedItem);我不知道,为什么是空的。
发布于 2015-10-10 22:17:12
我只需要修改一下
Form2 form = new Form2();到这个
Form2 form = new Form2(this);https://stackoverflow.com/questions/32997537
复制相似问题