Correct syntax in treeview attributes

G

Guest

For Each tn As TreeNode In TreeView1.SelectedNode.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_AfterSelect(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles
TreeView1.AfterSelect
If TreeView1.Nodes.IndexOf(TreeView1.SelectedNode) = -1 Then
TreeView1.SelectedNode.ForeColor = 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 ???
 
P

Phill W.

Nach said:
For Each tn As TreeNode In TreeView1.SelectedNode.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_AfterSelect( _
ByVal sender As System.Object,
, ByVal e As System.Windows.Forms.TreeViewEventArgs _
) Handles TreeView1.AfterSelect

If TreeView1.Nodes.IndexOf(TreeView1.SelectedNode) = -1 Then
TreeView1.SelectedNode.ForeColor = 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top