473,385 Members | 1,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

TreeView1_SelectedBeingAPain()

I am using a series of 8 TreeViews. If the root of the first one is in a selected state, I can still click any of the other node in another TreeView and it will remain selected. I have tried...

Protected Sub TreeView1_SelectedNodeChanged(ByVal sender////////////
if TreeView2.SelectedNode.Value = "yada" Then
blah
blah
blah
TreeView1.SelectedNode.Selected = False

but I get a NullReferenceExecption

Does anyone know how I can deselect all nodes in every TreeView ?
May 1 '07 #1
5 1155
SammyB
807 Expert 512MB
TreeView1.SelectedNode = Nothing
May 1 '07 #2
I tried that and I get the error "Property 'SelectedNode' is 'ReadOnly'
May 1 '07 #3
SammyB
807 Expert 512MB
I tried that and I get the error "Property 'SelectedNode' is 'ReadOnly'
Works for me. Put one tree view & one button on a new form. Add some nodes to the tree. Double-click the button & add code:
Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  3.         Me.TreeView1.SelectedNode = Nothing
  4.     End Sub
  5. End Class
  6.  
Are you using VB.NET 2005?
May 1 '07 #4
Works for me. Put one tree view & one button on a new form. Add some nodes to the tree. Double-click the button & add code:
Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  3.         Me.TreeView1.SelectedNode = Nothing
  4.     End Sub
  5. End Class
  6.  
Are you using VB.NET 2005?

yeah but I am getting a null reference exception, am not exactly sure why.
basically if no nodes are selected, when I do a SelectedNode.Selected = Nothing or False I get the error, obviously because there were no other nodes selected. I have tried an else if but that didn't work. The node being called to deselect need to be selected first.
But I have tried to check its state first but even still, as soon as it looks to see if it is true....WHAM
May 4 '07 #5
okay, I figured out that I needed to return the statement to terminate execution of the method. Yes I am a newb, but heyit works.

conlusion, don't forget to return the method to keep away from a null reference.
May 7 '07 #6

Sign in to post your reply or Sign up for a free account.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.