Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Highlighting a default treeview node

Highlighting a default treeview node

Scheduled Pinned Locked Moved C#
question
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BDJones
    wrote on last edited by
    #1

    How do you highlight a treeview node at startup? I have the node needed from BuildNodeTree() as defaultNode, and the following in frmMain_Load

    private void frmMain_Load(object sender, EventArgs e)
    {
    BuildNodeTree();
    treeview.SelectedNode = defaultNode;
    }

    This doesn't highlight the node. I'm assuming because it hasn't displayed yet. What are my options? Thank you.

    L P 2 Replies Last reply
    0
    • B BDJones

      How do you highlight a treeview node at startup? I have the node needed from BuildNodeTree() as defaultNode, and the following in frmMain_Load

      private void frmMain_Load(object sender, EventArgs e)
      {
      BuildNodeTree();
      treeview.SelectedNode = defaultNode;
      }

      This doesn't highlight the node. I'm assuming because it hasn't displayed yet. What are my options? Thank you.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Nope. Having treeview.SelectedNode = treeview.Nodes[0]; inside a Form_Load() handler is sufficient provided the TreeView has focus. A lot of Windows Controls don't mark their selections when they don't have focus. One way of getting there automatically is by making sure treeview.TabStop is true (default) and TabIndex is zero. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


      I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


      B L 2 Replies Last reply
      0
      • L Luc Pattyn

        Nope. Having treeview.SelectedNode = treeview.Nodes[0]; inside a Form_Load() handler is sufficient provided the TreeView has focus. A lot of Windows Controls don't mark their selections when they don't have focus. One way of getting there automatically is by making sure treeview.TabStop is true (default) and TabIndex is zero. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


        B Offline
        B Offline
        BDJones
        wrote on last edited by
        #3

        TabIndex = 0 That was it. Thank you again for your help today.

        1 Reply Last reply
        0
        • B BDJones

          How do you highlight a treeview node at startup? I have the node needed from BuildNodeTree() as defaultNode, and the following in frmMain_Load

          private void frmMain_Load(object sender, EventArgs e)
          {
          BuildNodeTree();
          treeview.SelectedNode = defaultNode;
          }

          This doesn't highlight the node. I'm assuming because it hasn't displayed yet. What are my options? Thank you.

          P Offline
          P Offline
          puri keemti
          wrote on last edited by
          #4

          Selecting node is highlighted by default. you can note that by change the background of the form.

          1 Reply Last reply
          0
          • L Luc Pattyn

            Nope. Having treeview.SelectedNode = treeview.Nodes[0]; inside a Form_Load() handler is sufficient provided the TreeView has focus. A lot of Windows Controls don't mark their selections when they don't have focus. One way of getting there automatically is by making sure treeview.TabStop is true (default) and TabIndex is zero. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


            I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Setting HideSelection to false highlights the selection (although dimmed) even when the control does not have focus. Most windows controls have a HideSelection property.

            L 1 Reply Last reply
            0
            • L Lost User

              Setting HideSelection to false highlights the selection (although dimmed) even when the control does not have focus. Most windows controls have a HideSelection property.

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              :thumbsup:

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


              I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups