WPF Treeview - How do I prevent a treeview item from collapse when pressing the minus key on the key pad

Posted on 2012-08-16
Last Modified: 2012-08-17
Hi Experts,

I have a WPF  application with a Treeview.  What I want to know is how do I prevent a treeviewitem from collapsing when pressing the minus key on the key pad?

When the minus key is pressed on the main part of the keyboard, it works just fine, but the other minus key on the # pad collpases the currently selected treeviewitem.

Question by:OFGemini

    Accepted Solution


            private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
                if (e.Key == Key.Subtract)
                    var tb = sender as TextBox;                
                    int selStart = tb.SelectionStart;
                    string before = tb.Text.Substring(0, selStart);
                    string after = tb.Text.Substring(before.Length);
                    tb.Text = string.Concat(before, "-", after);
                    tb.SelectionStart = before.Length + 1;
                    e.Handled = true;                

    Author Closing Comment

    the above link helped me...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now