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# / August 2006

Tip: Looking for answers? Try searching our database.

Another Newbie Question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sherri - 14 Aug 2006 15:24 GMT
I need to be able to delete a tree node by clicking on the Delete key
on the keyboard. (Basically, clicking on the Delete key calls a method
which performs the delete.)  An explanation and/or example would be
very much appreciated.
Nicholas Paldino [.NET/C# MVP] - 14 Aug 2006 15:33 GMT
Sherri,

   What you need to do is subscribe to the KeyUp event for the treeview.
Then, in that handler, if the delete key is pressed, get the current node,
and pass it to the Remove method on the TreeNodeCollection that it belongs
to.

   Hope this helps.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

>I need to be able to delete a tree node by clicking on the Delete key
> on the keyboard. (Basically, clicking on the Delete key calls a method
> which performs the delete.)  An explanation and/or example would be
> very much appreciated.
sherri - 14 Aug 2006 15:53 GMT
Thanks Nicholas!

How do I tell which key was pressed? (The rest seems very
straightforward.)
> Sherri,
>
[quoted text clipped - 13 lines]
> > which performs the delete.)  An explanation and/or example would be
> > very much appreciated.
Mini-Tools Timm - 14 Aug 2006 16:17 GMT
> Thanks Nicholas!
>
> How do I tell which key was pressed? (The rest seems very
> straightforward.)

I'd recommend watching for the KeyDown event.  You can get which key was
pressed in the KeyEventArgs object as follows:

    private void MtMessageBalloon_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Delete)
        {
            // handle delete key
        }
    }

Signature

Timm Martin
Mini-Tools
.NET Components and Windows Software
http://www.mini-tools.com

Mini-Tools Timm - 14 Aug 2006 16:18 GMT
> Thanks Nicholas!
>
> How do I tell which key was pressed? (The rest seems very
> straightforward.)

I'd recommend watching for the KeyDown event.  You can get which key was
pressed in the KeyEventArgs object as follows:

    private void TreeView_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Delete)
        {
            // handle delete key
        }
    }

Signature

Timm Martin
Mini-Tools
.NET Components and Windows Software
http://www.mini-tools.com


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.