Results 1 to 9 of 9

Thread: [RESOLVED] Treeview Node Font

  1. #1

    Thread Starter
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Resolved [RESOLVED] Treeview Node Font

    I have been looking around and can't seem to figure this out. I guess I'm confuse. But here goes

    I am processing thru the SSISDB catalog in SQL Server and adding nodes to a tree view. I can add all the nodes with out a problem and then seem to be correct and make sense when I compare the view in SSMS. Now my question. One of the parameters in an SSIS package is set by referencing an Environment variable (not a problem so far I can understand that this is referencing the environment). I want to change the font of this node only to underline and that is my question. How do I change the font of just this node to be underlined.

    Thanks
    Gary
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Treeview Node Font

    I *think* you should be able to do it by accessing the Font property of that specific TreeViewItem... I think...
    You should be able to create a new font instance using the current font as a template and flipping on the underline flag, and then assign that back to the Font property for that specific TreeViewItem.
    It should work.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Treeview Node Font

    Each TreeNode has a NodeFont property.

    Getting an underlined font is weird, because you can't really change a Font on the fly. Supposing you already had the node you wanted, it'd look something like:
    Code:
    Dim oldFont = node.NodeFont
    Dim newFont As new Font(oldFont, FontStyle.Underline)
    node.NodeFont = newFont
    There's one quirk you might run into: if a TreeNode's Font property is Nothing, it uses the TreeView's Font, so you might have better results relying on that. My code above might toss a NullReferenceException.

  4. #4

    Thread Starter
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Treeview Node Font

    Thanks Sitten

    here is what I did:
    vb.net Code:
    1. Dim f As New Font("Microsoft Sans Serif", 8, FontStyle.Underline)
    2. Dim f2 As New Font(f, FontStyle.Bold)
    3. tvCatalog.Nodes(0).Nodes(intNodeId).Nodes(intNode2).Nodes(intProjectNode).Nodes(intProjParmNode).Nodes(intlocalNode).Nodes.Add("SetEV", "Set From Enviorment Variable: " & drProjParams.GetString(7), 1)
    4. tvCatalog.Nodes(0).Nodes(intNodeId).Nodes(intNode2).Nodes(intProjectNode).Nodes(intProjParmNode).Nodes(intlocalNode).Nodes(intlocalNode).BackColor = Color.PaleTurquoise
    5. tvCatalog.Nodes(0).Nodes(intNodeId).Nodes(intNode2).Nodes(intProjectNode).Nodes(intProjParmNode).Nodes(intlocalNode).Nodes(intlocalNode).NodeFont = f2
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Treeview Node Font

    Why this
    Code:
    Dim f As New Font("Microsoft Sans Serif", 8, FontStyle.Underline)
    Dim f2 As New Font(f, FontStyle.Bold)
    when this works:
    Code:
    Dim f As New Font("Microsoft Sans Serif", 8, FontStyle.Underline & FontStyle.Bold)
    (to be fair, I can't remember if the flags should be & together or + together... one or both should work).

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6

    Thread Starter
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Treeview Node Font

    I need to correct... when I added the second font style I lost the underline. When I tried to do the FontStyle.Underline & FontStyle.Bold I get error:

    Severity Code Description Project File Line Suppression State
    Error BC30518 Overload resolution failed because no accessible 'New' can be called with these arguments:
    'Public Overloads Sub New(family As FontFamily, emSize As Single, style As FontStyle)': Value of type 'String' cannot be converted to 'FontFamily'.
    'Public Overloads Sub New(family As FontFamily, emSize As Single, style As FontStyle)': Option Strict On disallows implicit conversions from 'Integer' to 'FontStyle'.
    'Public Overloads Sub New(family As FontFamily, emSize As Single, unit As GraphicsUnit)': Value of type 'String' cannot be converted to 'FontFamily'.
    'Public Overloads Sub New(family As FontFamily, emSize As Single, unit As GraphicsUnit)': Option Strict On disallows implicit conversions from 'Integer' to 'GraphicsUnit'.
    'Public Overloads Sub New(familyName As String, emSize As Single, style As FontStyle)': Option Strict On disallows implicit conversions from 'Integer' to 'FontStyle'.
    'Public Overloads Sub New(familyName As String, emSize As Single, unit As GraphicsUnit)': Option Strict On disallows implicit conversions from 'Integer' to 'GraphicsUnit'. MySSISDBBrowser C:\Users\gmazz\Documents\Visual Studio 2015\Projects\MySSISDBBrowser\MySSISDBBrowser\frmMain.vb 11 Active

    same with +
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  7. #7
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Treeview Node Font

    "&" is for String concatenation. "+" is for String concatenation and adding numbers.

    When you want to use bitwise operations, you have to use And or Or. Speaking in terms of English, "And" sounds right. Speaking in terms of how programming works, "Or" is right:
    Code:
    New Font(f, FontStyle.Bold Or FontStyle.Underline)

  8. #8
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Treeview Node Font

    Didn't see this:
    Quote Originally Posted by techgnome View Post
    Why this
    Code:
    Dim f As New Font("Microsoft Sans Serif", 8, FontStyle.Underline)
    Dim f2 As New Font(f, FontStyle.Bold)
    when this works:
    Code:
    Dim f As New Font("Microsoft Sans Serif", 8, FontStyle.Underline & FontStyle.Bold)
    (to be fair, I can't remember if the flags should be & together or + together... one or both should work).

    -tg
    Smart-aleck answer: because the '&' operator is only used for bitwise operations in C#.

    Other smart-aleck answer: because the first block of code doesn't try to make the text bold AND underlined, that constructor for Font() should read as follows: "Use the same font size and family as this font, but let me define a new style".

    Also: you can't misspell a font name when you use the original font as the "prototype".

    Also: MS Sans Serif was the default font for Win 3.1, it's time to move to Segoe UI or at least Tahoma.

    It's generally more common that you have a not-bold font you want to make bold, and it's a pain in the butt to grab all the other stuff you need to make the font. So this is a convenience overload. Not every project uses the same font throughout, and in situations like a RichTextBox you can have a multitude of Font objects in play.
    Last edited by Sitten Spynne; Mar 7th, 2017 at 02:05 PM.

  9. #9

    Thread Starter
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Treeview Node Font

    Thanks got it, I added that to get the look I wanted.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width