TreeViewItem.FindItemByName C# (CSharp) Method

FindItemByName() public method

public FindItemByName ( string name ) : TreeViewItem,
name string
return TreeViewItem,
    public TreeViewItem FindItemByName(string name)
    {
        foreach (TreeViewItem item in Items)
        {
            if (item.Header == name)
            {
                return item;
            }
        }

        return null;
    }

Usage Example

Example #1
0
    TreeViewItem AddPathToTreeItem(TreeViewItem item, AkWwiseProjectData.AkInformation AkInfo)
    {
        TreeViewItem parentItem = item;

        string path = "/" + RootItem.Header + "/" + item.Header;

        for (int i = 0; i < AkInfo.PathAndIcons.Count; i++)
        {
            AkWwiseProjectData.PathElement PathElem = AkInfo.PathAndIcons[i];
            TreeViewItem childItem = parentItem.FindItemByName(PathElem.ElementName);

            path = path + "/" + PathElem.ElementName;

            if (childItem == null)
            {
                if (i != AkInfo.PathAndIcons.Count - 1)
                {
                    childItem = parentItem.AddItem(PathElem.ElementName, new AkTreeInfo(0, Guid.Empty.ToByteArray(), PathElem.ObjectType), GetExpansionStatus(path));
                }
                else
                {
                    bool isDraggable = !(PathElem.ObjectType == AkWwiseProjectData.WwiseObjectType.STATEGROUP || PathElem.ObjectType == AkWwiseProjectData.WwiseObjectType.SWITCHGROUP);
                    childItem = parentItem.AddItem(PathElem.ElementName, isDraggable, GetExpansionStatus(path), new AkTreeInfo(AkInfo.ID, AkInfo.Guid, PathElem.ObjectType));
                }
            }

            AddHandlerEvents(childItem);
            parentItem = childItem;
        }

        return(parentItem);
    }