Update datagrid in a MDI child from a MDI child!!!URGENT HELP REQUIRED!!!
-
In brief...I've a MDI application with this MDI childs(at the moment all MDI childs are closed): 1)MDIFORM (MDI container) 2)FORM1 (MDI form child) 3)FORM2 (MDI form child) I press a menu on MDIFORM that opens FORM1. In FORM1 there is a texbox. On keyPress event of textbox I write in a MSAccess table what I'm writing in the textbox. On Load event of FORM1 I open FORM2 where is a datagrid. The code is: public class FORM1: System.Windows.Forms.Form { private FORM2 form2=null; private void FORM1_Load(object sender, System.EventArgs e) { if (this.form2==null) { this.form2=new FORM2(); this.form2.MdiParent=this.MdiParent; } this.form2.Show(); } private void InsertString(object sender, System.Windows.Forms.KeyPressEventArgs e) { // -- INSERT DB } } In FORM2 I've a datagrid where I show results written before in last MSAccess table.The code is this: public class FORM2 : System.Windows.Forms.Form { private System.ComponentModel.Container components = null; private System.Windows.Forms.DataGrid dataPreResult; public FORM2() { InitializeComponent(); } protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code private void InitializeComponent() { this.dataPreResult = new System.Windows.Forms.DataGrid(); ((System.ComponentModel.ISupportInitialize)(this.dataPreResult)).BeginInit(); this.SuspendLayout(); // // dataPreResult // this.dataPreResult.AllowSorting = false; this.dataPreResult.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.dataPreResult.DataMember = ""; this.dataPreResult.Dock = System.Windows.Forms.DockStyle.Fill; this.dataPreResult.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.dataPreResult.HeaderForeColor = System.Drawing.SystemColors.ControlText; this.dataPreResult.Location = new System.Drawing.Point(0, 0); this.dataPreResult.Name = "dataPreResult"; this.dataPreResult.ReadOnly = true; this.dataPreResult.RowHeaderWidth = 10; this.dataPreResult.Si
-
In brief...I've a MDI application with this MDI childs(at the moment all MDI childs are closed): 1)MDIFORM (MDI container) 2)FORM1 (MDI form child) 3)FORM2 (MDI form child) I press a menu on MDIFORM that opens FORM1. In FORM1 there is a texbox. On keyPress event of textbox I write in a MSAccess table what I'm writing in the textbox. On Load event of FORM1 I open FORM2 where is a datagrid. The code is: public class FORM1: System.Windows.Forms.Form { private FORM2 form2=null; private void FORM1_Load(object sender, System.EventArgs e) { if (this.form2==null) { this.form2=new FORM2(); this.form2.MdiParent=this.MdiParent; } this.form2.Show(); } private void InsertString(object sender, System.Windows.Forms.KeyPressEventArgs e) { // -- INSERT DB } } In FORM2 I've a datagrid where I show results written before in last MSAccess table.The code is this: public class FORM2 : System.Windows.Forms.Form { private System.ComponentModel.Container components = null; private System.Windows.Forms.DataGrid dataPreResult; public FORM2() { InitializeComponent(); } protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code private void InitializeComponent() { this.dataPreResult = new System.Windows.Forms.DataGrid(); ((System.ComponentModel.ISupportInitialize)(this.dataPreResult)).BeginInit(); this.SuspendLayout(); // // dataPreResult // this.dataPreResult.AllowSorting = false; this.dataPreResult.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.dataPreResult.DataMember = ""; this.dataPreResult.Dock = System.Windows.Forms.DockStyle.Fill; this.dataPreResult.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.dataPreResult.HeaderForeColor = System.Drawing.SystemColors.ControlText; this.dataPreResult.Location = new System.Drawing.Point(0, 0); this.dataPreResult.Name = "dataPreResult"; this.dataPreResult.ReadOnly = true; this.dataPreResult.RowHeaderWidth = 10; this.dataPreResult.Si
Uh...What you need to do is maybe set a timer in form 2 to refresh the data in the datagrid.. I have an app that I do something similar in, and all you need to do is call ReadResults() and do dataPreResult.Invalidate() (to make sure that it gets redrawn) every so often..I'm not 100% sure on that, but it should work. Here's the relevant code:
**Timer updateDataGrid = new Timer();** // add this to your object declarations public FORM2() { InitializeComponent(); **updateDataGrid.Interval = 60*1000; updateDataGrid.Tick += new EventHandler(doUpdate); updateDataGrid.Start();** // add the above 3 lines in the constructor to set the interval, the handler for the timer firing and to start it. updating every minute seems like a good time, but you can change that } private void doUpdate(object sender, EventArgs e) { ReadResults(); dataPreResult.Invalidate(); }
-
Uh...What you need to do is maybe set a timer in form 2 to refresh the data in the datagrid.. I have an app that I do something similar in, and all you need to do is call ReadResults() and do dataPreResult.Invalidate() (to make sure that it gets redrawn) every so often..I'm not 100% sure on that, but it should work. Here's the relevant code:
**Timer updateDataGrid = new Timer();** // add this to your object declarations public FORM2() { InitializeComponent(); **updateDataGrid.Interval = 60*1000; updateDataGrid.Tick += new EventHandler(doUpdate); updateDataGrid.Start();** // add the above 3 lines in the constructor to set the interval, the handler for the timer firing and to start it. updating every minute seems like a good time, but you can change that } private void doUpdate(object sender, EventArgs e) { ReadResults(); dataPreResult.Invalidate(); }
No way...nothing happens...:sigh: