Windows Develop Bookmark and Share   
 index > Windows Forms General > Calling Controls in Second From
 

Calling Controls in Second From

I have two forms in my application. I used

Form2 frm = new Form2();

frm.Show();

to show the Second From.
How Can I populate the Data in datagrid in from 2 from Form1

in Vb
I can Write like
From2.text1.text = form1.text1.text

NewtoCsharp2008  Tuesday, September 20, 2005 7:42 PM
You could mark the controls as internal or public (they're protected by default), which would allow you to access them from other forms in your application. This can lead to a relatively brittle design changes to the form's implementation can break other code. (i.e. Changing a textbox to a dropdown list changes the method of access the content.) I would prefer to see a solution such as a property or method on Form2 that would allow you to access this data. For instance:

class Form2 : Form {
//...
  public string CompanyName {
    get {
      return tbCompanyName.Text;   // If implementation or field name ever changes, then change it once right here.
    }
  }
//...
}

In Form1:
form1.textBox1.Text = form2.CompanyName;
James Kovacs  Tuesday, September 20, 2005 7:48 PM

You can use google to search for other answers

Custom Search

More Threads

• Clearing Array's Rows and Column Count
• print rdlc reports automatically
• ToolStripMenuItem.EnabledChanged not firing when Enabled=true
• Transaction/connection control at the business layer?
• Making Variables Global.
• Drawing to a non-static panel from a static class.
• OutOfMemoryException was unhandled in datatable
• How Can I make the event of Activate Windows to run only one time?
• Newbie: Email a note/Report
• HtmlDocument copy, click