![](/img/trans.png)
[英]how to transfer selected item in listbox in form2 to textbox in form1 when i double click on particular item
[英]Take selected item from listbox in form2 and put it to Form1 to TextBox
我正在嘗試從Form2的 ListBox中獲取takeselectedItem並將其放入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);
我不知道為什么它為空。
我只需要對此進行修改
Form2 form = new Form2();
對此
Form2 form = new Form2(this);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.