![](/img/trans.png)
[英]sending datatable value to another form and create a loop and shown it in dgv
[英]sending value to another form
從form2中的文本框發送值到form1中的列表框時 ,我收到NullReferenceException
錯誤。
處理程序代碼是:
public void button1_Click(object sender, EventArgs e) {
ListBox LB = Application.OpenForms["Form1"].Controls["Project_list"] as ListBox;
LB.Items.Add(Project_name.Text);
}
它出了什么問題?
僅用於演示目的...檢查此代碼,設置斷點並查看發生的情況。
public void button1_Click(object sender, EventArgs e)
{
// i do assume there is a class Form1 within your project?!
Form1 frm = (Form1) Application.OpenForms["Form1"];
// look for Project_list within your Form1.Controls, true to search all childControls too
Control[] ctrls = frm.Controls.Find("Project_list", true);
if (ctrls.Length >0)
{
ListBox LB = ctrls[0] as ListBox;
if (LB!=null)
LB.Items.Add(Project_name.Text);
else
System.Diagnostics.Debug.WriteLine("Doooooh");
}
}
這只是一個例子,可以看出你的代碼有什么問題!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.