Note that there are some explanatory texts on larger screens.

plurals
  1. POFormClosing delegate event problem
    text
    copied!<p>I have two forms named 'mainForm' and 'addRslt'. The idea is when users click on a button in mainForm, the addRslt form will Show() and then user will populate a TreeView. Now when user WANT to <strong>CLOSE</strong> this addRslt form, program will instead <strong>Hide()</strong> the form (using <strong>e.Cancel = true;</strong> ) so later if user reopen this he/she can add more things to the TreeView.</p> <p>In my mainForm I have a button for showing this addRslt form, and also inside this button's click code, there is my FormClosing delegte which will detect and copy the contents od TreeView in addRslt form to a TreeView in mainForm.</p> <p>Now the problem is I want to check for duplicated Nodes and do not add them to TreeView in mainForm. This is done right, but I also have a message box that tells the user that program had not added existing nodes! thats ok till now.. <strong>BUT</strong> problem is with each time I do this, this messagebox will appear N+1 times! I mean if I do it for first time, this message box appears 2 time and etc...</p> <p>Here is my code! Sorry for long story!</p> <pre><code> private void menuFileAddTestResults_Click(object sender, EventArgs e) { addRslt.Show(); addRslt.FormClosing += delegate { foreach (TreeNode node in addRslt.treeViewSelectedFiles.Nodes) { TreeNode newNode = new TreeNode(); newNode.Text = node.Text; newNode.Name = node.Name; newNode.Tag = node.Tag; if (!treeViewTestFiles.Nodes.ContainsKey(node.Name)) { treeViewTestFiles.Nodes.Add(newNode); } else { countExist++; } } if (countExist &gt; 0) { MessageBox.Show(countExist.ToString() + " Test files are already exist in the list!"); } countExist = 0; }; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload