Get Active mdichild form
-
how to loop through Application openforms and get specified form which is active with note that may be more than one form with the same name is running Form ActvFrm = this.ActiveMdiChild; string cptn = ActvFrm.Name; FrmNewPatiant FNew = (FrmNewPatiant)Application.OpenForms["FrmNewPatiant"]; foreach (Form FrmNew in Application.OpenForms) { if (FrmNew.Text == cptn) { FrmNewPatiant actvNewPat = (FrmNewPatiant)Application.OpenForms[cptn]; actvNewPat.tabNewFile.TabPages[2].Enabled = true; actvNewPat.tabNewFile.SelectedTab = FNew.tabNewFile.TabPages[2]; } }
-
how to loop through Application openforms and get specified form which is active with note that may be more than one form with the same name is running Form ActvFrm = this.ActiveMdiChild; string cptn = ActvFrm.Name; FrmNewPatiant FNew = (FrmNewPatiant)Application.OpenForms["FrmNewPatiant"]; foreach (Form FrmNew in Application.OpenForms) { if (FrmNew.Text == cptn) { FrmNewPatiant actvNewPat = (FrmNewPatiant)Application.OpenForms[cptn]; actvNewPat.tabNewFile.TabPages[2].Enabled = true; actvNewPat.tabNewFile.SelectedTab = FNew.tabNewFile.TabPages[2]; } }
What I used to do was store a value typically the id of the record or individual. I stored this value as the tag value of the child form created. In this way you can make certain not to replicate already created or open form by comparing this value to be created with the values stored in all of the currently open and active forms. I now use Tabs instead of MDI in most of my applications though which is why I said used.
-
What I used to do was store a value typically the id of the record or individual. I stored this value as the tag value of the child form created. In this way you can make certain not to replicate already created or open form by comparing this value to be created with the values stored in all of the currently open and active forms. I now use Tabs instead of MDI in most of my applications though which is why I said used.
-
This is how I did it when using MDI. I used a Tree View control populated with A-Z subnodes would be names organized last to first with a comma and middle initial, and I would store the id of the record containing the information in the tag element of the Tree View like so.
private void updateTreeview()
{
//add letters sort nodes
for (int i = System.Convert.ToInt32('A'); i <= System.Convert.ToInt32('Z'); i++)
{
treeView1.Nodes.Add(Convert.ToString((char)(i)), Convert.ToString((char)(i))); //set key and text
}//add customers TreeNode childnode = null; string sContactsName = null; foreach (DataRow rowContacts in dtContacts.Rows) { sContactsName = string.Concat(rowContacts\["LastName"\].ToString(), ", ", rowContacts\["FirstName"\].ToString()); if (!(System.Convert.IsDBNull(rowContacts\["MiddleInitial"\].ToString()))) { sContactsName = string.Concat(sContactsName, " ", rowContacts\["MiddleInitial"\].ToString(), "."); } //---------------------Key lines here -------------- childnode = new TreeNode(sContactsName, 0, 1); childnode.Name = sContactsName; //set text as key childnode.Tag = rowContacts\["ContactID"\].ToString(); //-------------------------------------------------- string sortnode = sContactsName.Substring(0, 1).ToUpper(); //gets alphabet sort node by first letter treeView1.Nodes\[sortnode\].Nodes.Add(childnode); } //Update TreeView treeView1.Visible = true; treeView1.Enabled = true; treeView1.ExpandAll(); }
After the node containing the name was clicked I handled it like this:
private void treeView1\_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { string nodeName = e.Node.Name; if (nodeName.Length == 1) { return; //is alphabet sort node, exit } //see if child form already exists and show it foreach (Form f in this.MdiChildren) { if (f.Name == nodeName) { f.Activate(); return; } } str