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. Visual Basic
  4. VB.Net: Setting the SelectedNode and SelectedItem font in Treeview and Listview Controls

VB.Net: Setting the SelectedNode and SelectedItem font in Treeview and Listview Controls

Scheduled Pinned Locked Moved Visual Basic
csharphelp
2 Posts 1 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.
  • M Offline
    M Offline
    Mbire
    wrote on last edited by
    #1

    Hi guys, I am struggling to change the font style of a selected node in a treeview and a selected item in a listview control, your help is very much appreciated. Regards:~

    M 1 Reply Last reply
    0
    • M Mbire

      Hi guys, I am struggling to change the font style of a selected node in a treeview and a selected item in a listview control, your help is very much appreciated. Regards:~

      M Offline
      M Offline
      Mbire
      wrote on last edited by
      #2

      Got it and a bit embarrassed, its amazingly simple. here are my lines, I used the **AfterSelect** event of the TreeView to set the font of the node, its parent and all its ancestors to bold, when another node is selected, i set the new node and its ancestors to bold, while returning the previously selected node to the normal font of the TreeView . By removing the while... statement in both methods, only the selected node is set to bold and back to normal. I know there are most likely better solutions but this one works fine.

      Dim previousSelectedNode as TreeNode
      ...
      ...
      Private Sub Treeview1_AfterSelect(ByVal sender As System.Object, ByVal e As _ System.Windows.Forms.TreeViewEventArgs) Handles Treeview1.AfterSelect
              Dim xnode As TreeNode
              If previousSelectedNode IsNot Nothing Then DeSelectNode()
              e.Node.NodeFont = New Font(Treeview1.Font, FontStyle.Bold)
              xnode = e.Node
              While xnode.Parent IsNot Nothing
                  xnode = xnode.Parent
                  xnode.NodeFont = New Font(Treeview1.Font, FontStyle.Bold)
              End While
              previousSelectedNode = e.Node
      End Sub
      

      'Deselecting a node Private Sub DeSelectNode() previousSelectedNode.NodeFont = Treeview1.Font While previousSelectedNode.Parent IsNot Nothing previousSelectedNode = previousSelectedNode.Parent previousSelectedNode.NodeFont = Treeview1.Font End While End Sub

      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