Esempio n. 1
0
        internal void CollapseInternal()
        {
            if (IsInATreeListView)
            {
                if (ListView.InvokeRequired)
                {
                    throw new Exception("Invoke Required");
                }
            }
            TreeListViewItem selItem = null;

            if (TreeListView != null)
            {
                selItem = TreeListView.FocusedItem;
            }
            // The item was expanded -> raise an event
            if (Visible && _IsExpanded && ListView != null)
            {
                TreeListViewCancelEventArgs e = new TreeListViewCancelEventArgs(this, TreeListViewAction.Collapse);
                ListView.RaiseBeforeCollapse(e);
                if (e.Cancel)
                {
                    return;
                }
            }

            // Collapse
            if (this.Visible)
            {
                foreach (TreeListViewItem item in Items)
                {
                    item.Hide();
                }
            }

            // The item was expanded -> raise an event
            if (Visible && _IsExpanded && IsInATreeListView)
            {
                this._IsExpanded = false;
                TreeListViewEventArgs e = new TreeListViewEventArgs(this, TreeListViewAction.Collapse);
                ListView.RaiseAfterCollapse(e);
                if (AfterCollapse != null)
                {
                    AfterCollapse(this);
                }
            }
            this._IsExpanded = false;
            if (IsInATreeListView && selItem != null)
            {
                if (selItem.Visible)
                {
                    selItem.Focused = true;
                }
                else
                {
                    ListView listview = (ListView)TreeListView;
                    listview.SelectedItems.Clear();
                    TreeListViewItem[] items = selItem.ParentsInHierarch;
                    for (int i = items.Length - 1; i >= 0; i--)
                    {
                        if (items[i].Visible)
                        {
                            items[i].Focused = true;
                            break;
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        internal void ExpandInternal()
        {
            if (IsInATreeListView)
            {
                if (ListView.InvokeRequired)
                {
                    throw new Exception("Invoke Required");
                }
            }

            TreeListViewItem selItem = null;

            if (TreeListView != null)
            {
                selItem = TreeListView.FocusedItem;
            }

            // Must set ListView.checkDirection to CheckDirection.None.
            // Forbid recursively checking.
            CheckDirection oldDirection = CheckDirection.All;

            if (ListView != null)
            {
                oldDirection            = this.ListView.CheckDirection;
                ListView.CheckDirection = CheckDirection.None;
            }

            // The item wasn't expanded -> raise an event
            if (Visible && !_IsExpanded && ListView != null)
            {
                TreeListViewCancelEventArgs e = new TreeListViewCancelEventArgs(this, TreeListViewAction.Expand);
                ListView.RaiseBeforeExpand(e);
                if (e.Cancel)
                {
                    return;
                }
            }

            if (Visible)
            {
                for (int i = Items.Count - 1; i >= 0; i--)
                {
                    TreeListViewItem item = this.Items[i];
                    if (!item.Visible)
                    {
                        ListView listView = this.ListView;
                        listView.Items.Insert(this.Index + 1, item);
                        item.SetIndentation();
                    }
                    if (item.IsExpanded)
                    {
                        item.Expand();
                    }
                }
            }
            // The item wasn't expanded -> raise an event
            if (Visible && !_IsExpanded && IsInATreeListView)
            {
                this._IsExpanded = true;
                TreeListViewEventArgs e = new TreeListViewEventArgs(this, TreeListViewAction.Expand);
                ListView.RaiseAfterExpand(e);
                if (AfterExpand != null)
                {
                    AfterExpand(this);
                }
            }
            this._IsExpanded = true;

            // Reset ListView.checkDirection
            if (IsInATreeListView)
            {
                ListView.CheckDirection = oldDirection;
            }
            if (TreeListView != null && selItem != null)
            {
                if (selItem.Visible)
                {
                    selItem.Focused = true;
                }
            }
        }