Mike

Mike

  • NA
  • 2
  • 0

.NET and AfterCheck event ?

Jan 16 2006 9:51 PM
Has anyone tried the AfterCheck event in .NET v2.0?

It appears to be broken, but it is possible I am doing something wrong.

I have a simple routine to add a path name to an ArrayList if a tree node is checked and another ArrayList if a tree node is unchecked.  The crazy thing is, if a node is "expanded", the AfterCheck event is obviously being fired because I end up with an entry in the checked ArrayList. There happens to a checked subnode within the expanded part of the treeview. The AfterCheck event should NOT be firing on a node expand.  What gives Microsoft or am I just hallucinating?

I have a FolderTree class which includes the following:

public ArrayList CheckedNodes = new ArrayList();
public ArrayList UncheckedNodes = new ArrayList();

Then I have an event capture setup as:

AfterCheck += new TreeViewEventHandler(tallyCheck_Uncheck);

I also happen to have two other events coded just before this event so it reads as follows:

BeforeExpand += new TreeViewCancelEventHandler(prepare);
AfterCollapse += new TreeViewEventHandler(clear);
AfterCheck += new TreeViewEventHandler(tallyCheck_Uncheck);

(I have included these other events because I am not sure whether they can in some way affect each other. Incidentally these other events do not reference in any way the ArrayLists mentioned above)

Here is the content of the "tallyCheck_Uncheck" method:

 private void tallyCheck_Uncheck(object sender, TreeViewEventArgs e)
 {
    if (e.Node.Checked)
       CheckedNodes.Add(e.Node.FullPath);
    else
       UncheckedNodes.Add(e.Node.FullPath);
 }

When I sample this by simply doing the following:

foreach (string newItem in fileTree1.CheckedNodes)
{
     MessageBox.Show("NewItem: " + newItem);
}

fileTree1 is defined as:

private FolderTree fileTree1;

newItem shows a checked item on a node expand. I would have expected this to occur ONLY when a node is checked.

Comments?