Windows Develop Bookmark and Share   
 index > Windows Forms General > Passing data from one form to the next??
 

Passing data from one form to the next??

HI all,
My first post ever os giv me some feedback plz.
I have one form(main form) which when i click on a button opens another form(table form), in this form
the user presses a button and i want to send the text from this button back to the other form(main form).
I tried creating a new instance of the main form but that didn't work. I also tried creating a public class with
a public string to store it in but i have to create a new instance of this class in each form, meaning i cant get the data i want.
Very frustrating >_<
Main Form:

private void tableForm()

{

FormTables TableForm = new FormTables();

TableForm.Show();

}

Table form:

FormDetails detailsForm = new FormDetails();

private void loadTables()

{

for (int i = 1; i < 31; i++)

{

Button buttontables = new Button();

buttontables.Size = new System.Drawing.Size(86, 71);

buttontables.UseVisualStyleBackColor = true;

buttontables.Text = i.ToString();

buttontables.Click += new System.EventHandler(this.buttonTables_Click);

flowLayoutPanel1.Controls.Add(buttontables);

}

}

private void buttonTables_Click(object sender, EventArgs e)

{

Button clickedButton = (Button)sender;

detailsForm.Table = clickedButton.Text;

//dont know how to send it back to the main form...

}

public class FormDetails

{

string table;

public string Table

{

get { return table; }

set { table = value; }

}

}

Tuigin  Friday, May 18, 2007 5:11 AM

Hi,

this should help point you in the right direction: http://themightycoder.spaces.live.com/blog/cns!EBFBA22CD769E10B!144.entry

Mark.

Mark Dawson  Friday, May 18, 2007 6:34 AM

Hi,

this should help point you in the right direction: http://themightycoder.spaces.live.com/blog/cns!EBFBA22CD769E10B!144.entry

Mark.

Mark Dawson  Friday, May 18, 2007 6:34 AM
Hi,
That was exactly what i was looking for.
I didn't know you could use showdialog instead of show.
Thanks heaps.
Tuigin  Sunday, May 20, 2007 9:22 PM

You can use google to search for other answers

Custom Search

More Threads

• change all application windows icons in one place
• C#
• Custom Smart tags.
• Quick Question - Showing a background image on a control?
• MDI that looks like vb.net studio or photoshop
• noob: Load Config.XML file
• SendKeys help
• DataGrid Delete Row Problem -- EditMode=EditOnEnter
• Snipping Tool, Erasing parts of the Selected Area.
• .sln reader