//Get Tag of selected nodes in treeteaview /// <summary> /// Casts the Tags of all currently selected nodes to the type T, but only returns the succesfully casted tags (=only where tag is of type T) /// </summary> /// <typeparam name="T"></typeparam> /// <param name="self"></param> /// <returns>Returns only the tags, where the tag actually is of type T</returns> public static IEnumerable <T> GetSelectedTags <T>(this TreeTeaView self) { List <T> data = new List <T>(); foreach (TreeNode node in self.SelectedNodes) { if (node.Tag is T) { data.Add((T)node.Tag); } } return(data); }
/// <summary> /// Tries to cast the Tag of the all currently selected nodes to the type T and returns true if all nodes have been succesfully casted. Returns only succesfully casted tags (=only whea tag is T) /// </summary> /// <typeparam name="T"></typeparam> /// <param name="self"></param> /// <param name="data"></param> /// <returns>True if all the Tags of the selected nodes are of type T</returns> public static bool GetSelectedTags <T>(this TreeTeaView self, out IEnumerable <T> data) { List <T> tmp = new List <T>(); bool allSuccessfullyCasted = true; foreach (TreeNode node in self.SelectedNodes) { if (node.Tag is T) { tmp.Add((T)node.Tag); } else { allSuccessfullyCasted = false; } } data = tmp; return(allSuccessfullyCasted); }
/// <summary> /// Returns true if all the Tags of the any currently selected nodes are of type T /// </summary> /// <typeparam name="T"></typeparam> /// <param name="self"></param> /// <returns></returns> public static bool IsSelectedTagsOfType <T>(this TreeTeaView self) { return(self.SelectedNodes.All(x => x.Tag is T)); }
/// <summary> /// Checks whether all currently selected nodes are of type T /// </summary> /// <typeparam name="T">Must be derived class of TreeNode</typeparam> /// <param name="treeView"></param> /// <returns>True if the selected node is of type T</returns> public static bool IsSelectedNodesOfType <T>(this TreeTeaView treeView) where T : TreeNode { return(treeView.SelectedNodes.All((node) => node is T)); }
/// <summary> /// Returns a collection of all currently selected nodes, which are of type T /// </summary> /// <typeparam name="T">Must be derived class of TreeNode</typeparam> /// <param name="treeView"></param> /// <returns></returns> public static IEnumerable <T> GetSelectedNodesOfType <T>(this TreeTeaView treeView) where T : TreeNode { return(treeView.SelectedNodes.OfType <T>()); }