Correct syntax in treeview attributes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?TmFjaA==?=

    #1

    Correct syntax in treeview attributes

    For Each tn As TreeNode In TreeView1.Selec tedNode.Nodes
    *** If tn.ForeColor = Color.Blue Then ***
    Does not like above line. Can you give the correct syntax ???
    I = I + 1
    End If
    Next tn

    Also in Treeview we have the after select as shown below

    Private Sub TreeView1_After Select(ByVal sender As System.Object,
    ByVal e As System.Windows. Forms.TreeViewE ventArgs) Handles
    TreeView1.After Select
    If TreeView1.Nodes .IndexOf(TreeVi ew1.SelectedNod e) = -1 Then
    TreeView1.Selec tedNode.ForeCol or = Color.Blue
    End If
    End Sub

    Do we have the same option in listview to turn certain lines a different color
    and then going thru the collection to examine the lines that were changed ???



  • Phill W.

    #2
    Re: Correct syntax in treeview attributes

    Nach wrote:
    For Each tn As TreeNode In TreeView1.Selec tedNode.Nodes
    *** If tn.ForeColor = Color.Blue Then ***
    Does not like above line. Can you give the correct syntax ???
    You can't set individual properties on any Font object; you have to
    create whole new ones:

    Dim f As New Font( tn.Font )
    f.Color = Color.Blue
    tn.Font = f

    Also in Treeview we have the after select as shown below
    >
    Private Sub TreeView1_After Select( _
    ByVal sender As System.Object,
    , ByVal e As System.Windows. Forms.TreeViewE ventArgs _
    ) Handles TreeView1.After Select
    >
    If TreeView1.Nodes .IndexOf(TreeVi ew1.SelectedNod e) = -1 Then
    TreeView1.Selec tedNode.ForeCol or = Color.Blue
    End If
    >
    End Sub
    What do you expect the above to do?

    Change the selected Node to be Blue? Use the e.Node property:

    e.Node.Font = ...

    To reset all the others to "not Blue", you either have to loop through
    the Nodes Collection [of the selected Node] and reset the colour, or use
    the BeforeSelect event to "reset" the old one, before AfterSelect "sets"
    the new one (I think! - haven't tried it).

    Also, be aware that TreeView1.Nodes *only* contains the Nodes at the
    /root/ of the Tree - each Node has its own collection of child Nodes, as
    you work your way down the tree.

    HTH,
    Phill W.

    Comment

    Working...