tags:

views:

70

answers:

2

Hi,

I am using treeview in C# and VS2005

if ((tempnode1 = tempnode1.NextVisibleNode) != null);

I am not able to handle the null reference returned by this statement at the last node of the treeview. Can anyone please suggest a statement to check for null returned by TreeNode.NextVisibleNode

Thanks.

+2  A: 

Get rid of the semicolon at the end of the "if" line.

Filip Navara
... and, in general, don't try to do several things all at once. This kind of code is bad for readability. Put the assignment on a separate line.
Pavel Minaev
+1  A: 

How about something like ...

if( tempnode1 != null && tempnode1.NextVisibleNode != null )
{
  tempnode1 = tempnode1.NextVisibleNode;
}

It's a bit more defensive and a bit more readable.

JP Alioto
Thanks JP. Works fine now.
VP
You're welcome, glad to help!
JP Alioto