/// <summary> /// 根据完全路径获取对应的节点(路径不分大小写) /// </summary> /// <param name="fullpath"></param> /// <returns></returns> public virtual KellNode GetNodeByFullPath(string fullpath) { KellNode node = null; if (fullpath.EndsWith(pathSpliteChar.ToString())) { fullpath = fullpath.Substring(0, fullpath.Length - 1); } int level = fullpath.Split(new char[1] { pathSpliteChar }).Length; int thisLevel = this.FullPath.Split(new char[1] { pathSpliteChar }).Length; if (thisLevel == level) {//对比当前层 if (this.FullPath.ToLower() == fullpath.ToLower()) { node = this; } } else if (thisLevel < level) {//往下找 node = GetDown(this, fullpath); } else {//往上找 node = GetUp(this, fullpath); } return(node); }
private void LoadType(KellNode node) { if (node != null) { loadover = false; this.SuspendLayout(); comboBox1.Items.Clear(); subComboBoxs.Clear(); this.Controls.RemoveByKey("SubCombo"); List <KellNode> types = node.GetSub(); foreach (KellNode type in types) { comboBox1.Items.Add(type); } if (comboBox1.Items.Count > 0) { comboBox1.SelectedIndex = 0; } if (addNewType) { comboBox1.Items.Add(NewItemString); } //SetSubType(types); this.ResumeLayout(true); loadover = true; } }
public virtual KellNode GetNodeByID(string id, bool ignoreCase) { KellNode kellNode = null; foreach (KellNode node in this.children) { if (ignoreCase) { if (node.ID.ToLower() == id.ToLower()) { kellNode = node; break; } else { GetNodeByID(id, true); } } else { if (node.ID == id) { kellNode = node; break; } else { GetNodeByID(id, false); } } } return(kellNode); }
public List <KellNode> GetFirstChildCycle(KellNode node) { List <KellNode> typeLink = new List <KellNode>(); if (node != null) { KellNode child = node.FirstNode; if (child != null) { int i = child.Level + 1; if (!child.IsLeaf) { typeLink.Add(child); CreateNewComboBoxTip(i); GetFirstChildCycle(child); } else { typeLink.Add(child); CreateNewComboBoxTip(i); } } } return(typeLink); }
private void SelectItem(object item) { if (IsLevelNode) { KellNode node = (KellNode)item; if (node != null) { if (node.IsLeaf) { if (!listBox2.Items.Contains(node)) { listBox2.Items.Add(node); listBox1.Items.Remove(node); } } else { DownLevel(node); } } } else { if (!listBox2.Items.Contains(item)) { listBox2.Items.Add(item); listBox1.Items.Remove(item); } } }
private void CancelSelect(object item) { if (IsLevelNode) { KellNode node = (KellNode)item; if (node != null) { if (node.Level == this.node.Level + 1) { if (!listBox1.Items.Contains(node)) { listBox1.Items.Add(node); listBox2.Items.Remove(node); } } else { listBox2.Items.Remove(node); } } } else { if (!listBox1.Items.Contains(item)) { listBox1.Items.Add(item); listBox2.Items.Remove(item); } } }
private void DownLevel(KellNode node) { if (node != null && !node.IsLeaf) { comboBox1.Text = node.FullPath; Goto(); } }
public KellLinkComboBox(KellNode node, bool addNewType = false) { InitializeComponent(); AddNewType = addNewType; tt = new ToolTip(); tt.SetToolTip(comboBox1, " "); tt.Popup += new PopupEventHandler(tt_Popup); subComboBoxs = new List <ComboBoxTip>(); LoadRootNode(node); }
private void SelectComboBoxItem(ComboBox combo, KellNode node) { for (int i = 0; i < combo.Items.Count; i++) { if (((KellNode)combo.Items[i]).ID == node.ID) { combo.SelectedIndex = i; break; } } }
/// <summary> /// 获取指定节点以下有几层(深度) /// </summary> /// <param name="node"></param> /// <param name="deepth"></param> /// <returns></returns> protected static int GetDeepth(KellNode node, ref int deepth) { foreach (KellNode nod in node.children) { while (!nod.IsLeaf) { int newDeepth = GetDeepth(nod, ref deepth); if (newDeepth > deepth) { deepth = newDeepth; } } } return(deepth); }
private void LoadRootNode(KellNode node) { this.node = node; if (node != null) { LoadType(node); List <KellNode> typeLink = GetFirstChildCycle(node); SelectComboBoxItem(comboBox1, typeLink[0]); for (int i = 1; i < typeLink.Count; i++) { SelectComboBoxItem(subComboBoxs[i].Combo, typeLink[i]); } for (int i = typeLink.Count; i < subComboBoxs.Count; i++) { subComboBoxs[i].Combo.Visible = false; } } }
protected static KellNode GetDown(KellNode node, string path) { KellNode getit = null; if (node != null) { foreach (KellNode nod in node.children) { string currpath = nod.FullPath.ToLower(); if (currpath == path.ToLower()) { return(nod); } if (path.ToLower().StartsWith(currpath) && !nod.IsLeaf) { getit = GetDown(nod, path); } } } return(getit); }
protected static KellNode GetUp(KellNode node, string path) { KellNode getit = null; if (node != null) { KellNode parent = node.Parent; if (parent != null) { string currpath = parent.FullPath.ToLower(); if (currpath == path.ToLower()) { return(parent); } if (currpath.StartsWith(path.ToLower()) && !parent.IsRoot) { getit = GetUp(parent, path); } } } return(getit); }
private void Goto() { if (this.node != null) { KellNode node = this.node.GetNodeByFullPath(comboBox1.Text); if (node != null) { listBox1.Items.Clear(); listBox1.Items.AddRange(node.GetSub().ToArray()); comboBox1.Text = node.FullPath; this.node = node; } if (node.IsRoot) { button6.Enabled = false; } else { button6.Enabled = true; } } }
public void RemoveChildByID(string id) { KellNode node = GetNodeByID(id, false); children.Remove(node); }
public void AddChild(KellNode node) { children.Add(node); node.parent = this; }
private void LoadSubType(ComboBox combo) { if (combo.SelectedItem == null) { return; } if (!(combo.SelectedItem.GetType().Equals(Type))) { combo.Visible = false; int level = subComboBoxs.IndexOfComboBox(combo); for (int i = level; i < subComboBoxs.Count; i++) { subComboBoxs[i].Combo.Visible = false; } } else { KellNode parent = (KellNode)combo.SelectedItem; int level = parent.Level; for (int i = subComboBoxs.Count; i < parent.LevelCount - 2; i++) { CreateNewComboBoxTip(i); } for (int i = level - 1; i < subComboBoxs.Count; i++) { if (parent != null) { List <KellNode> subs = parent.GetSub(); if (subs.Count > 0) { subComboBoxs[i].Combo.Visible = true; subComboBoxs[i].Combo.Items.Clear(); foreach (KellNode sub in subs) { subComboBoxs[i].Combo.Items.Add(sub); } subComboBoxs[i].Combo.Items.Add(UpLevelString); if (addNewType) { subComboBoxs[i].Combo.Items.Add(NewItemString); } subComboBoxs[i].Combo.Items.Add(UpLevelString); subComboBoxs[i].Combo.SelectedIndex = 0; } else { subComboBoxs[i].Combo.Visible = false; } List <KellNode> subs1 = parent.GetSub(); if (subs1.Count > 0) { parent = subs1[0]; } else { parent = null; } } } } }