I replied (twice in fact, with example) on this topic yesterday; it
looks like nntp swallowed them...
But as Alvin hints - you need to use the *same* DataSet (or other
model) instance in both forms for changes to be immeditely visible -
otherwise you'll need to do a lot of manual juggling. This could be by
passing a DataSet into the form, rather than creating one per form.
Some hasty re-typing... (below)
Marc
using System;
using System.Data;
using System.Windows.Forms;
static class Program
{
static void Main()
{
DataSet data = new DataSet("MyDataSet");
DataTable table = data.Tables.Add("MyDataTable");
table.Columns.Add("Name", typeof(string));
table.Columns.Add("DateOfBirth", typeof(DateTime));
table.Rows.Add("Fred", DateTime.Today);
table.Rows.Add("Jo", DateTime.Today.AddDays(-30));
Application.EnableVisualStyles();
MyForm form1 = new MyForm(),
form2 = new MyForm();
form1.Text = "Form 1";
form2.Text = "Form 2";
form1.DataMember = form2.DataMember = "MyDataTable";
form1.DataSource = form2.DataSource = data;
form1.Load += delegate { form2.Show(form1); };
Application.Run(form1);
}
}
class MyForm : Form
{
DataGridView grid;
public MyForm() {
InitializeComponent();
}
public string DataMember
{
get {return grid.DataMember;}
set {grid.DataMember = value;}
}
public object DataSource
{
get {return grid.DataSource;}
set {grid.DataSource = value;}
}
void InitializeComponent() {
grid = new DataGridView();
grid.Dock = DockStyle.Fill;
Controls.Add(grid);
}
}