|
Hello,
I have two forms. The first form (Form1) contains a textbox and button. The second one (Form2) contains a combo and button. when the button on the form1 is pressed, form2 will be active. Then the user should choose some value from the combobox and press the button in the form2. When this button is pressed, the selected value from the combobox should be displayed in the textbox in the first form, and the second form should close itself. The problem is displaying the selected text in the textbox in the first form. Please help
Thanks |
| Barbi Rio Friday, September 04, 2009 10:58 AM |
// in form1
Form2 form2 = new Form2(textBox1.Text);
if (form2.ShowDialog(this) == DialogResult.OK)
textBox2.Text = form2.Selection;
// in form2
private string selection;
public string Selection { get { return selection; } }
button1_Click(object sender, EventArgs e)
{
selection = comboBox1.SelectedText;
// may need to use comboBox1.SelectedItem.ToString(), I forget
DialogResult = DialogResult.OK; // will close form for you
}
- Marked As Answer byLing WangMSFT, ModeratorSunday, September 13, 2009 9:19 AM
-
|
| ScottyDoesKnow Friday, September 04, 2009 3:59 PM |
- Marked As Answer byLing WangMSFT, ModeratorSunday, September 13, 2009 9:19 AM
-
|
| Christoph Wagner Friday, September 04, 2009 11:47 AM |
you can simply use form2.combobox1.selectedtext, to get the selected text and display the same in form1... Vicky- Marked As Answer byLing WangMSFT, ModeratorSunday, September 13, 2009 9:19 AM
-
|
| Vikram Gorla Friday, September 04, 2009 1:11 PM |
Another method uses the delegate:
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/12d4df45-d9ba-4fe3-9af0-8c7ca31681d0
Best regards,
Ling Wang
Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. - Marked As Answer byLing WangMSFT, ModeratorSunday, September 13, 2009 9:19 AM
-
|
| Ling Wang Friday, September 11, 2009 7:31 AM |
Assign the selected text property to a static variable in the common class. when form2 closes access that property to get value and show it in form1 - Marked As Answer byLing WangMSFT, ModeratorSunday, September 13, 2009 9:19 AM
-
|
| Hassan Mehmood Friday, September 11, 2009 7:38 AM |
- Marked As Answer byLing WangMSFT, ModeratorSunday, September 13, 2009 9:19 AM
-
|
| Christoph Wagner Friday, September 04, 2009 11:47 AM |
you can simply use form2.combobox1.selectedtext, to get the selected text and display the same in form1... Vicky- Marked As Answer byLing WangMSFT, ModeratorSunday, September 13, 2009 9:19 AM
-
|
| Vikram Gorla Friday, September 04, 2009 1:11 PM |
// in form1
Form2 form2 = new Form2(textBox1.Text);
if (form2.ShowDialog(this) == DialogResult.OK)
textBox2.Text = form2.Selection;
// in form2
private string selection;
public string Selection { get { return selection; } }
button1_Click(object sender, EventArgs e)
{
selection = comboBox1.SelectedText;
// may need to use comboBox1.SelectedItem.ToString(), I forget
DialogResult = DialogResult.OK; // will close form for you
}
- Marked As Answer byLing WangMSFT, ModeratorSunday, September 13, 2009 9:19 AM
-
|
| ScottyDoesKnow Friday, September 04, 2009 3:59 PM |
Another method uses the delegate:
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/12d4df45-d9ba-4fe3-9af0-8c7ca31681d0
Best regards,
Ling Wang
Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. - Marked As Answer byLing WangMSFT, ModeratorSunday, September 13, 2009 9:19 AM
-
|
| Ling Wang Friday, September 11, 2009 7:31 AM |
Assign the selected text property to a static variable in the common class. when form2 closes access that property to get value and show it in form1 - Marked As Answer byLing WangMSFT, ModeratorSunday, September 13, 2009 9:19 AM
-
|
| Hassan Mehmood Friday, September 11, 2009 7:38 AM |