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?
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.
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.
精彩评论