I’m doing a winform which consist a listbox (listbox10) with some items on it. When I doubleclick an item, it will show another form (Form3) which consist a textbox (textbox1) and the textbox’s text is the item I select. Below is my coding.
Form3 msgForm3;
private void listBox10_DoubleClick(object sender, EventArgs e)
{
msgForm3 = new Form3();
textBox1.Text = listBox10.SelectedItem.ToString();
msgForm3.Show();
}
But somehow I don’t know why, the textbox is always empty. Anything wrong with my coding?
The
textBox1you are accessing is not onmsgForm3. to access the one onmsgForm3use (as the other answers have mentioned)but since all form controls are
privateby default you can either change its protection level insideForm3.Designer.cstopublic(orinternal) :or add the text that should go in
textbox1as a parameter in Form3 constructor :and when your create an instance of Form3 use