Accessing data controls between different forms in C #

XmlDataDocument xmlDatadoc = new XmlDataDocument();

xmlDatadoc.DataSet.ReadXml(dir + listBox1.SelectedItem);

DataSet ds = new DataSet("Customer info");

ds = xmlDatadoc.DataSet;

dataGridView1.DataSource = ds.DefaultViewManager;

dataGridView1.DataMember = "Customer";

Now, if the ListBox control "listBox1" is in a different form, say "form1" of the application, how can I get the data and use it in the datagrid in "Form2"?

+3
source share
1 answer

To my knowledge, the following methods should be as follows.

  • Use properties in the target form and assign it when creating an instance of the class
  • Pass the data source in the constructor of the target form.
  • You are now in Form2, and here is another way: Form1.ListBox.YourpropertyName;
  • Delegates can be used, but this expensive memory must also be disposed of after use.
  • , .

, .

, 3 , . 5 ​​ .

0

All Articles