Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / November 2007

Tip: Looking for answers? Try searching our database.

Treeview Aftercheck

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pbaugh@recoilsoft.com - 13 Nov 2007 16:47 GMT
Hi Folks,
I've got a treeview control (trvRecipes) and am attempting to detect
the 'checking' of a nodes checkbox in order to check all the child
nodes. Ive found some sample code to do precisely this on MSDN, but
for some reason the event never seems to get raised....

       private void trvRecipes_AfterCheck(object sender,
TreeViewEventArgs e)
       {
           // The code only executes if the user caused the checked
state to change.
           if (e.Action != TreeViewAction.Unknown)
           {
               if (e.Node.Nodes.Count > 0)
               {
                   /* Calls the CheckAllChildNodes method, passing in
the current
                   Checked value of the TreeNode whose checked state
changed. */
                   this.CheckAllChildNodes(e.Node, e.Node.Checked);
               }
           }
       }

Im sure its just something obvious Im missing.... any ideas??

Many many thanks
Pete
Chris Shepherd - 13 Nov 2007 16:59 GMT
> Hi Folks,
> I've got a treeview control (trvRecipes) and am attempting to detect
> the 'checking' of a nodes checkbox in order to check all the child
> nodes. Ive found some sample code to do precisely this on MSDN, but
> for some reason the event never seems to get raised....
[...]
> Im sure its just something obvious Im missing.... any ideas??

Do you have the EventHandler defined for the AfterCheck event?

Chris.
pbaugh@recoilsoft.com - 13 Nov 2007 17:08 GMT
> pba...@recoilsoft.com wrote:
> > Hi Folks,
[quoted text clipped - 8 lines]
>
> Chris.

Hi Chris,
I do but I may well have made a complete mess of it! (Apologies for
being an VB developer on a steep learning curve!)

The code Ive got is :

   public partial class frmRecipeImport : Form
   {
       public event TreeViewEventHandler AfterCheck;
       ... etc

Wrong place?? wrong code??

Thanks
Pete
Chris Shepherd - 13 Nov 2007 17:15 GMT
> Hi Chris,
> I do but I may well have made a complete mess of it! (Apologies for
> being an VB developer on a steep learning curve!)
[...]

> Wrong place?? wrong code??

Heheh, I hear ya. It's the wrong code basically.

If you look in the properties of the TreeView in the designer, there's
the Events listing (lightning bolt in your properties window), which is
one way to get at the events. Double clicking inside the value cell in
that list will either create the event handler for you, or take you to
it in code if you already have one.

In the designer.cs file, you should see a section of code with a comment
of "trvRecipe" at the top, where it assigns a bunch of properties to the
object.
In there, you can add a line like:

trvRecipe.AfterCheck += new TreeViewEventhandler(trvRecipe_AfterCheck);

One thing to watch out for, if you have a habit of cut and pasting form
elements, cutting them will remove all the event subscription code.

Chris.
pbaugh@recoilsoft.com - 13 Nov 2007 17:40 GMT
> Heheh, I hear ya. It's the wrong code basically.
>
[quoted text clipped - 15 lines]
>
> Chris.

What a star! Yeah, I'd completely messed up the event handler. After
following your instructions, the whole thing worked perfectly first
time.

Many thanks!!
Pete

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.