zack
zack

Reputation: 7385

Finding if the next visible node exists

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

Answers (2)

JP Alioto
JP Alioto

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

Filip Navara
Filip Navara

Reputation: 4828

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

Upvotes: 2

Related Questions