1
TreeNode tnKey = 
    treeViewFilters
    .Nodes
    .Cast<TreeNode>()
    .Where(r => r.Text == FilterName)
    .ToArray()[0];

The above code is not working. It reports an error

Error   1   Instance argument: cannot convert from 'System.Windows.Forms.TreeNodeCollection' to 'System.Data.EnumerableRowCollection'   

Error   2   'System.Windows.Forms.TreeNodeCollection' does not contain a definition for 'Cast' and the best extension method overload 'System.Data.EnumerableRowCollectionExtensions.Cast<TResult>(System.Data.EnumerableRowCollection)' has some invalid arguments 

I have taken code from Is there a method for searching for TreeNode.Text field in TreeView.Nodes collection? Any ideas?

1
  • This works fine in linqpad for me (replacing treeViewFilters with new TreeView()) and ToArray()[0] with FirstOrDefault(). Commented Jul 26, 2013 at 14:12

1 Answer 1

1

Sorry my mistake, i forget to add 'system.linq' name space

Sign up to request clarification or add additional context in comments.

1 Comment

Mark this answer of yours as answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.