Treeview Node Loses highlight when context menu opens

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phill

    Treeview Node Loses highlight when context menu opens

    Here's what I'm doing to make the right context mnue show up based on
    what node was cliked:

    private void tvwMenu_MouseUp (object sender, MouseEventArgs e)
    {
    //Select Node When Right Clicked & Set Context Menu To Use
    if( e.Button == MouseButtons.Ri ght )
    {
    TreeNode node = tvwMenu.GetNode At( new Point( e.X, e.Y ) );
    if( node != null )
    {
    TreeNodeMenuTag tag = (TreeNodeMenuTa g)node.Tag;
    tvwMenu.Selecte dNode = node;
    tvwMenu.Context MenuStrip = (tag.isMenu) ? cmnuMenuNode :
    cmnuProgramNode ;
    }
    }
    }

    It works, but unlike the Solution Explorer treeview in VS when you
    right click on a node the node loses its highlight. I don't like this
    cux it makes it less obvious which node you are operating on. Anyone
    know how to fix this?

    Thanks.
  • Philip Rieck

    #2
    Re: Treeview Node Loses highlight when context menu opens

    Try setting the treeview's "Hide Selection" property to false.


    "Phill" <wackyphill@yah oo.com> wrote in message
    news:ac94631d.0 410060555.2c046 b75@posting.goo gle.com...[color=blue]
    > Here's what I'm doing to make the right context mnue show up based on
    > what node was cliked:
    >
    > private void tvwMenu_MouseUp (object sender, MouseEventArgs e)
    > {
    > //Select Node When Right Clicked & Set Context Menu To Use
    > if( e.Button == MouseButtons.Ri ght )
    > {
    > TreeNode node = tvwMenu.GetNode At( new Point( e.X, e.Y ) );
    > if( node != null )
    > {
    > TreeNodeMenuTag tag = (TreeNodeMenuTa g)node.Tag;
    > tvwMenu.Selecte dNode = node;
    > tvwMenu.Context MenuStrip = (tag.isMenu) ? cmnuMenuNode :
    > cmnuProgramNode ;
    > }
    > }
    > }
    >
    > It works, but unlike the Solution Explorer treeview in VS when you
    > right click on a node the node loses its highlight. I don't like this
    > cux it makes it less obvious which node you are operating on. Anyone
    > know how to fix this?
    >
    > Thanks.[/color]


    Comment

    • Phill

      #3
      Re: Treeview Node Loses highlight when context menu opens

      Thanks for the tip it does improve things having the highlight still
      show when the context menu takes focus.

      Still, you have to click like 2x in order to right click another node.
      Once to cause the context menu to loose focus and again to get the
      context menu to appear on the new node.

      In VS's Exlorer or even Windows Explorer though you don't have to.
      Just right clicking another node (eben if the context menu is already
      up) works.

      Any idea how to accomplish this?

      Comment

      • Philip Rieck

        #4
        Re: Treeview Node Loses highlight when context menu opens

        In your mousedown or up event handler (where you're determining what node
        was clicked on), you'll have to programmaticall y set the selection to that
        node. If you're relying on the treeview's selected node property, you'll
        have to abandon that and call the methods to get the node based on the mouse
        position.

        --
        -Philip Rieck


        -
        "Phill" <wackyphill@yah oo.com> wrote in message
        news:ac94631d.0 410070904.340c3 37d@posting.goo gle.com...[color=blue]
        > Thanks for the tip it does improve things having the highlight still
        > show when the context menu takes focus.
        >
        > Still, you have to click like 2x in order to right click another node.
        > Once to cause the context menu to loose focus and again to get the
        > context menu to appear on the new node.
        >
        > In VS's Exlorer or even Windows Explorer though you don't have to.
        > Just right clicking another node (eben if the context menu is already
        > up) works.
        >
        > Any idea how to accomplish this?[/color]


        Comment

        • Willian Sanada

          #5
          RE: Treeview Node Loses highlight when context menu opens

          Hello Phill, I'm Willian from Brazil ...

          You most change the mouse position for some context. You can use method
          PointToClient of treeview object. This method return a point in client
          context.
          For example:

          Point position = myTreeview.Poin tToClient(new Position(e.X, e.Y));
          TreeNode node = myTreeview.GetN odeAt(position) ;

          Try it!

          [ ]'s

          Willian



          "Phill" wrote:
          [color=blue]
          > Here's what I'm doing to make the right context mnue show up based on
          > what node was cliked:
          >
          > private void tvwMenu_MouseUp (object sender, MouseEventArgs e)
          > {
          > //Select Node When Right Clicked & Set Context Menu To Use
          > if( e.Button == MouseButtons.Ri ght )
          > {
          > TreeNode node = tvwMenu.GetNode At( new Point( e.X, e.Y ) );
          > if( node != null )
          > {
          > TreeNodeMenuTag tag = (TreeNodeMenuTa g)node.Tag;
          > tvwMenu.Selecte dNode = node;
          > tvwMenu.Context MenuStrip = (tag.isMenu) ? cmnuMenuNode :
          > cmnuProgramNode ;
          > }
          > }
          > }
          >
          > It works, but unlike the Solution Explorer treeview in VS when you
          > right click on a node the node loses its highlight. I don't like this
          > cux it makes it less obvious which node you are operating on. Anyone
          > know how to fix this?
          >
          > Thanks.
          >[/color]

          Comment

          Working...