Amit Garg
Amit Garg

Reputation: 59

Check Node in TreeView Control in C#

How can I check that the selected Node is a File or directory in a TreeView Control in C#?

I am working on window form in C#. I can check through the file extension but there are so many file extensions so it makes for a lengthy code. Can any body give me a small method for this?

Upvotes: 0

Views: 983

Answers (2)

Ashlesh
Ashlesh

Reputation: 11

You can use the node.GetType() property of the particular node to find out that it is directory or file. I.e.:

if (tree.SelectedNode.GetType() == typeof(FileNode))

Hope it helps.

Upvotes: 1

Rafal Spacjer
Rafal Spacjer

Reputation: 4918

You can use Tag property of the TreeNode to store information about node type - for example store there enum value, object or any other type that will be useful for you.

Upvotes: 0

Related Questions