Reputation: 7385
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.
Upvotes: 0
Views: 333
Reputation: 45127
How about something like ...
if( tempnode1 != null && tempnode1.NextVisibleNode != null )
{
tempnode1 = tempnode1.NextVisibleNode;
}
It's a bit more defensive and a bit more readable.
Upvotes: 1