/// <summary> /// Adds an item in the collection and in the TreeListView /// </summary> /// <param name="item"></param> /// <returns>Index of the item in the collection</returns> public virtual int Add(TreeListViewItem item) { if (TreeListView != null) { if (TreeListView.InvokeRequired) { throw(new Exception("Invoke required")); } } // Do not add the item if the collection owns a TreeListView recursively // and the item already owns a TreeListView if (TreeListView != null && item.ListView != null) { throw(new Exception("The Item is already in a TreeListView")); } int index = GetInsertCollectionIndex(item); if (index == -1) { return(-1); } if (Parent != null) { item.SetParent(Parent); } item.Items.Comparer = this.Comparer; int treelistviewindex = GetInsertTreeListViewIndex(item, index); // Insert in the ListView if (treelistviewindex > -1) { ListView listview = (ListView)TreeListView; listview.Items.Insert(treelistviewindex, (ListViewItem)item); if (item.IsExpanded) { item.Expand(); } item.SetIndentation(); } // Insert in this collection if (index > -1) { List.Insert(index, item); } if (index > -1) { OnItemAdded(new TreeListViewEventArgs(item, TreeListViewAction.Unknown)); } if (Count == 1 && TreeListView != null && Parent != null) { if (Parent.Visible) { Parent.Redraw(); } } return(index); }
/// <summary> /// Adds an item in the collection and in the TreeListView /// </summary> /// <param name="item"></param> /// <returns>Index of the item in the collection</returns> public virtual int Add(TreeListViewItem item) { if(TreeListView != null) if(TreeListView.InvokeRequired) throw(new Exception("Invoke required")); // Do not add the item if the collection owns a TreeListView recursively // and the item already owns a TreeListView if(TreeListView != null && item.ListView != null) throw(new Exception("The Item is already in a TreeListView")); int index = GetInsertCollectionIndex(item); if(index == -1) return(-1); if(Parent != null) item.SetParent(Parent); item.Items.Comparer = this.Comparer; int treelistviewindex = GetInsertTreeListViewIndex(item, index); // Insert in the ListView if(treelistviewindex > -1) { ListView listview = (ListView) TreeListView; listview.Items.Insert(treelistviewindex, (ListViewItem) item); if(item.IsExpanded) item.Expand(); item.SetIndentation(); } // Insert in this collection if(index > -1) List.Insert(index, item); if(index > -1) OnItemAdded(new TreeListViewEventArgs(item, TreeListViewAction.Unknown)); if(Count == 1 && TreeListView != null && Parent != null) if(Parent.Visible) Parent.Redraw(); return(index); }
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 = 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 LView = this.ListView; LView.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; } } }
private void SetStateByHiddenCol(TreeListViewItem node) { bool Checked = Apq.Convert.ChangeType<bool>(node.SubItems[node.ListView.Columns.Count + 1].Text); bool Expanded = Apq.Convert.ChangeType<bool>(node.SubItems[node.ListView.Columns.Count + 2].Text); bool Selected = Apq.Convert.ChangeType<bool>(node.SubItems[node.ListView.Columns.Count + 3].Text); node.Checked = Checked; if (Expanded) node.Expand(); if (Selected) node.Selected = true; foreach (TreeListViewItem tln in node.Items) { SetStateByHiddenCol(tln); } }
/// <summary>m /// 构造树根节点 /// </summary> /// <param name="tree"></param> /// <param name="p_productId"></param> private void treeRootCreate(TreeListView tree, string p_productId,string name) { TreeListViewItem root = new TreeListViewItem(name, 0); root.Expand(); tree.Items.Add(root); treeChildCreate(root, p_productId); // this.list_productTreeStruct; }
/// <summary> /// 初始化树列表根节点 /// </summary> private void list_productTreeStruct_init() { TreeListViewItem root = new TreeListViewItem(this.m_product.PRODUCTNO, 0); root.Expand(); root.SubItems.Add(this.m_product.VERSION); this.list_productTreeStruct.Items.Add(root); treeCreater(root, this.m_product.PRODUCTID); }
/// <summary> /// 查询按钮操作 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void bt_StructSearch_Click(object sender, EventArgs e) { //1.清空列表显示 this.list_productTreeStruct.Items.Clear(); //2.判断查询条件是否为空(为空显示完整的产品结构树,否则显示符合条件的产品结构) if (this.tb_structProValue.Text.Trim() == "") { list_productTreeStruct_init(); } else { TreeListViewItem root = new TreeListViewItem(this.m_product.PRODUCTNO, 0); root.Expand(); root.SubItems.Add(this.m_product.VERSION); this.list_productTreeStruct.Items.Add(root); string id = treeCreaterSearch(root, this.m_product.PRODUCTID); treeCreater(root, id); } }