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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Set a node in a Treeview to bold

Set a node in a Treeview to bold

Scheduled Pinned Locked Moved C#
graphicsquestionannouncement
4 Posts 3 Posters 3 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.
  • G Offline
    G Offline
    Gian
    wrote on last edited by
    #1

    I'm trying to set the text of an item of a TreeView to bold. When i set the node font, the node continues to use the same width space for drawing the text as where the font was "plain", so the label is trunked at the end. There's a way to update correctly the space of the node? i've used this code before adding the node to the Nodes collection: TreeNode node = new TreeNode("Test", 0, 0); node.NodeFont = new Font(treeView.Font, FontStyle.Bold); treeView.Nodes.Add(node);

    B 1 Reply Last reply
    0
    • G Gian

      I'm trying to set the text of an item of a TreeView to bold. When i set the node font, the node continues to use the same width space for drawing the text as where the font was "plain", so the label is trunked at the end. There's a way to update correctly the space of the node? i've used this code before adding the node to the Nodes collection: TreeNode node = new TreeNode("Test", 0, 0); node.NodeFont = new Font(treeView.Font, FontStyle.Bold); treeView.Nodes.Add(node);

      B Offline
      B Offline
      Baris Kurtlutepe
      wrote on last edited by
      #2

      Yes there is a workaround: node.Font = new Font(someotherfont..); node.Text = node.Text; I know it looks silly, but it's the only workaround I found to force the treeview to recalculate the size of text with the new font/style etc.

      H 1 Reply Last reply
      0
      • B Baris Kurtlutepe

        Yes there is a workaround: node.Font = new Font(someotherfont..); node.Text = node.Text; I know it looks silly, but it's the only workaround I found to force the treeview to recalculate the size of text with the new font/style etc.

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        This makes sense, since setting the Text property actually causes the class to send the TVM_SETITEM message to the underlying Tree-View common control with the TVIF_TEXT flag to set the text. If you set the text first, the underlying tree view probably isn't sent the text mask and hence the text is not sent. This would best be called a bug, but why it is necessary does make sense if you understand how the TreeView class works (i.e., it encapsulates its respective common control, as do most controls in Windows Forms).

        Microsoft MVP, Visual C# My Articles

        G 1 Reply Last reply
        0
        • H Heath Stewart

          This makes sense, since setting the Text property actually causes the class to send the TVM_SETITEM message to the underlying Tree-View common control with the TVIF_TEXT flag to set the text. If you set the text first, the underlying tree view probably isn't sent the text mask and hence the text is not sent. This would best be called a bug, but why it is necessary does make sense if you understand how the TreeView class works (i.e., it encapsulates its respective common control, as do most controls in Windows Forms).

          Microsoft MVP, Visual C# My Articles

          G Offline
          G Offline
          Gian
          wrote on last edited by
          #4

          i cant see any differencies using that workaround. However i'm setting the new font before adding the node to the treeview, so the text area'd must be already recalculated, or not?

          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