private List <string> getTreeNodeContent(TreeListViewItemCollection items) { List <string> list = new List <string>(); string line = ""; int level = 0; foreach (TreeListViewItem treeNode in items) { line = treeNode.Text; if (!line.TrimStart().StartsWith("#")) { line += ": "; level = Convert.ToInt32(treeNode.SubItems[2].Text); line = YmlFormatUtil.GetSpace(level * 4) + line; line += treeNode.SubItems[1].Text; line += treeNode.SubItems[3].Text; } if (!string.IsNullOrWhiteSpace(line)) { list.Add(line); } list.AddRange(getTreeNodeContent(treeNode.Items)); } return(list); }
public void PopulateTree(XElement element, TreeListViewItemCollection items) { foreach (XElement node in element.Nodes()) { TreeListViewItem item = new TreeListViewItem(); string title = node.Name.LocalName.Trim(); item.Text = title; if (title == "Device") { var attr = node.Attribute("ItemType")?.Value; switch (attr) { case "Channel": item.ImageIndex = 1; break; case "RStreamer": item.ImageIndex = 3; break; default: break; } item.SubItems.Add(node.Attribute("UniqueID")?.Value); item.SubItems.Add(node.Attribute("ItemType")?.Value); } else { item.ImageIndex = 2; item.SubItems.Add(node.Attribute("Value")?.Value); } if (node.HasElements) { PopulateTree(node, item.Items); } items.Add(item); } }
private static void SaveNodes(TreeListViewItemCollection nodesCollection, XmlTextWriter textWriter) { for (int i = 0; i < nodesCollection.Count; i++) { TreeListViewItem node = nodesCollection[i]; //relative path textWriter.WriteStartElement(XmlNodeTag); textWriter.WriteAttributeString(XmlNodeFullPath, node.fullPath); textWriter.WriteAttributeString(XmlNodeIsFolderAtt, node.isfolder.ToString()); textWriter.WriteAttributeString(XmlNodeRelativePath, node.Text); textWriter.WriteAttributeString(XmlNodeRating, node.rating.ToString()); textWriter.WriteAttributeString(XmlNodeSizeAtt, node.nodeSize.kb.ToString()); if (node.Items.Count > 0) { SaveNodes(node.Items, textWriter); } textWriter.WriteEndElement(); } }
private void bt_comp_Click(object sender, EventArgs e) { TreeListViewItemCollection list_first = this.tlv_treeFirst.Items[0].Items; TreeListViewItemCollection list_second = this.tlv_treeSecond.Items[0].Items; int firstLen = list_first.Count; int secondLen = list_second.Count; int minLen; if (firstLen > secondLen) { minLen = secondLen; } else { minLen = firstLen; } for (int i = 0; i < minLen; i++) { setRowColor(list_first[i], list_second[i]); } for (int m = minLen; m < firstLen; m++) { changeColor(list_first[m], Color.Lime); } for (int n = minLen; n < secondLen; n++) { changeColor(list_second[n], Color.Lime); } //Color.FromArgb(255, 128, 0) }
public static void SetImages(TreeListViewItemCollection TLVIC, bool showicon, ref ImageList imageList1) { foreach (TreeListViewItem TLVI2 in TLVIC) { SetImage(TLVI2, showicon, ref imageList1); SetImages(TLVI2.Items, showicon, ref imageList1); } }
private void SetAllRes(List <Neusoft.Privilege.BizLogic.Model.Priv> allRes, TreeListViewItemCollection itemsList) { foreach (TreeListViewItem item in itemsList) { allRes.Add(item.Tag as Priv); SetAllRes(allRes, item.Items); } }
public void LoadItems <T>(IEnumerable <T> items, TreeListViewItemCollection Items, Func <T, string> getId, Func <T, string> getParentId, Func <T, string> getDisplayName, Func <T, int> getImageIndex, List <string> lstPropertyName) { //List<string> lstPropertyName = new List<string>(); Items.Clear(); dictItems.Clear(); foreach (var item in items) { var id = getId(item); var displayName = getDisplayName(item); var imageIndex = -1; if (getImageIndex != null) { imageIndex = getImageIndex(item); } var treeListViewItem = new TreeListViewItem(); treeListViewItem.Name = id; treeListViewItem.Text = displayName; treeListViewItem.Tag = item; if (imageIndex >= 0) { treeListViewItem.ImageIndex = imageIndex; } foreach (string propertyName in lstPropertyName) { object obj = PublicMethods.GetPropertyValue(item, propertyName);; string str = ""; if (obj != null) { str = obj.ToString(); } treeListViewItem.SubItems.Add(str); } dictItems.Add(id, treeListViewItem); } foreach (var id in dictItems.Keys) { var item = GetItem(id); var obj = (T)item.Tag; var parentId = getParentId(obj); if (parentId != null) { var parentNode = GetItem(parentId.ToString()); parentNode.Items.Add(item); } else { Items.Add(item); } } }
private void InitCheckBox(TreeListViewItemCollection currentItemList) { foreach (TreeListViewItem currentItem in currentItemList) { if (currentItem != null) { currentItem.Checked = false; InitCheckBox(currentItem.Items); } } }
private void SetChildNode(Boolean Judge, TreeListViewItemCollection ChildNodes) { if (ChildNodes == null) { return; } foreach (TreeListViewItem item in ChildNodes) { item.Checked = Judge; SetChildNode(Judge, item.Items); } }
private void SetCheckBox(TreeListViewItemCollection currentItemList, Priv res) { foreach (TreeListViewItem currentItem in currentItemList) { if ((currentItem.Tag as Priv).Id == res.Id) { currentItem.Checked = true; } if (currentItem != null) { SetCheckBox(currentItem.Items, res); } } }
/// <summary> /// Constructor /// </summary> /// <param name="collection"></param> public TreeListViewItemsEditorForm(TreeListViewItemCollection collection) { InitializeComponent(); _items = collection; treeView1.SelectedNode = null; foreach (TreeListViewItem item in _items) { TreeNode node = new TreeNode(item.Text); node.Tag = item; treeView1.Nodes.Add(node); AddChildren(node); node.Expand(); } }
private TreeListViewItem getTreeNode(TreeListViewItemCollection items, string uuid) { TreeListViewItem node = null; YmlItem item = null; foreach (TreeListViewItem treeNode in items) { item = (YmlItem)treeNode.Tag; if (item.Uuid == uuid) { node = treeNode; return(node); } node = getTreeNode(treeNode.Items, uuid); if (null != node) { return(node); } } return(null); }
private TreeListViewItem FindNode(int taskId, TreeListViewItemCollection nodes) { foreach (TreeListViewItem node in nodes) { if ((int)node.Tag == taskId) { return(node); } else { if (node.Items.Count > 0) { TreeListViewItem childnode = FindNode(taskId, node.Items); if (childnode != null) { return(childnode); } } } } return(null); }
/// <summary> /// Constructor /// </summary> /// <param name="collection"></param> public TreeListViewItemsEditorForm(TreeListViewItemCollection collection) { InitializeComponent(); _items = collection; treeView1.SelectedNode = null; foreach(TreeListViewItem item in _items) { TreeNode node = new TreeNode(item.Text); node.Tag = item; treeView1.Nodes.Add(node); AddChildren(node); node.Expand(); } }
internal void AddRangeInternal(TreeListViewItemCollection collection) { foreach(TreeListViewItem item in collection) Add(item); }
/// <summary> /// Adds a collection to this collection /// </summary> /// <param name="collection"></param> public void AddRange(TreeListViewItemCollection collection) { if(TreeListView != null) TreeListView.BeginUpdate(); AddRangeInternal(collection); if(TreeListView != null) TreeListView.EndUpdate(); }
/// <summary> /// Adds a collection to this collection /// </summary> /// <param name="collection"></param> public void AddRange(TreeListViewItemCollection collection) { collection.ReadWriteLock.AcquireReaderLock(-1); foreach(TreeListViewItem item in collection) Add(item); collection.ReadWriteLock.ReleaseReaderLock(); }
private TreeListViewItem FindNode(int taskId, TreeListViewItemCollection nodes) { foreach (TreeListViewItem node in nodes) { if ((int)node.Tag == taskId) { return node; } else { if (node.Items.Count > 0) { TreeListViewItem childnode = FindNode(taskId, node.Items); if (childnode != null) return childnode; } } } return null; }
public TreeListEx() { InitializeComponent(); _items = new TreeListViewItemCollection(this); base.MultiSelect = false; }
/// <summary> /// Gets the items that are visible in the TreeListView /// </summary> /// <returns>A collection of items</returns> public TreeListViewItemCollection GetVisibleItems() { TreeListViewItemCollection visibleItems = new TreeListViewItemCollection(); if(base.Items.Count == 0) return visibleItems; if (TopItem == null) return visibleItems; int firstItemIndex = TopItem.Index; int itemsPerPageCount = APIsUser32.SendMessage(new HandleRef(this, Handle), (int) APIsEnums.ListViewMessages.GETITEMCOUNT, IntPtr.Zero, IntPtr.Zero).ToInt32(); int lastVisibleItemIndex = firstItemIndex + itemsPerPageCount > base.Items.Count ? base.Items.Count : firstItemIndex + itemsPerPageCount; for(int i = firstItemIndex; i < lastVisibleItemIndex; i++) visibleItems.Add((TreeListViewItem) base.Items[i]); return visibleItems; }
/// <summary> /// Create a new instance of a TreeListView /// </summary> public TreeListView() { InitializeComponent(); if(!IsHandleCreated) CreateHandle(); _items = new TreeListViewItemCollection(this); _items.SortOrder = _sorting; _comctl32Version = APIsComctl32.GetMajorVersion(); IntPtr stylePtr = APIsUser32.SendMessage(new HandleRef(this, Handle), (int) APIsEnums.ListViewMessages.GETEXTENDEDLISTVIEWSTYLE, IntPtr.Zero, IntPtr.Zero); int style = stylePtr.ToInt32(); style |= (int) (APIsEnums.ListViewExtendedStyles.INFOTIP | APIsEnums.ListViewExtendedStyles.LABELTIP); stylePtr = (IntPtr) style; APIsUser32.SendMessage(new HandleRef(this, Handle), (int) APIsEnums.ListViewMessages.SETEXTENDEDLISTVIEWSTYLE, IntPtr.Zero, stylePtr); }
private TreeListViewItem[] GetCheckedItems() { if(InvokeRequired) throw(new Exception("Invoke required")); TreeListViewItemCollection items = new TreeListViewItemCollection(); foreach(TreeListViewItem item in Items) item.GetCheckedItems(ref items); return(items.ToArray()); }
public void LoadPartItems <T, K>(IEnumerable <T> items, TreeListViewItemCollection Items, Func <T, string> getId, Func <T, string> getParentId, Func <T, string> getDisplayName, Dictionary <string, string> dictPropertyName, Func <T, int> getImageIndex, Func <T, Color> getForeColor) where K : class { this.BeginUpdate(); this.SuspendLayout(); #region 将TreeListViewItem放到字典中 this.Columns.Clear(); int columnWidth = (this.Width - 10) / (dictPropertyName.Count + 1); int coulumnCounter = 0; //先初始化列 foreach (KeyValuePair <string, string> dictItem in dictPropertyName) { ColumnHeader ch = new ColumnHeader(); ch.Text = dictItem.Value; if (coulumnCounter == 0) { ch.Width = columnWidth * 2; } else { ch.Width = columnWidth; } coulumnCounter++; this.Columns.Add(ch); } //再初始化数据行 foreach (var item in items) { var id = getId(item); var imageIndex = -1; if (getImageIndex != null) { imageIndex = getImageIndex(item); } var treeListViewItem = new TreeListViewItem(); treeListViewItem.Name = id; treeListViewItem.Tag = item; if (imageIndex >= 0) { treeListViewItem.ImageIndex = imageIndex; } treeListViewItem.ForeColor = getForeColor(item); K clsK = item as K; if (clsK != null) { #region TreeListViewItem int columnCounter = 0; foreach (KeyValuePair <string, string> dictItem in dictPropertyName) { object objValue = PublicMethods.GetPropertyValue(item, dictItem.Key); string strValue = objValue == null ? "" : objValue.ToString(); if (columnCounter == 0) { treeListViewItem.Text = strValue; } else { treeListViewItem.SubItems.Add(strValue); } columnCounter++; } #endregion } else { treeListViewItem.Text = getDisplayName(item); } dictItems.Add(id, treeListViewItem); } #endregion #region 将TreeListViewItem进行组装 foreach (var id in dictItems.Keys) { var item = GetItem(id); var obj = (T)item.Tag; var parentId = getParentId(obj); if (parentId != null) { var parentNode = GetItem(parentId.ToString()); parentNode.Items.Add(item); } else { Items.Add(item); } } #endregion this.ResumeLayout(true); this.EndUpdate(); }
/// <summary> /// Create a new instance of a TreeListViewItem /// </summary> public TreeListViewItem() { _items = new TreeListViewItemCollection(this); }
public void LoadItems <T, K>(IEnumerable <T> items, TreeListViewItemCollection Items, Func <T, string> getId, Func <T, string> getParentId, Func <T, string> getDisplayName, Dictionary <string, string> dictPropertyName, Func <T, int> getImageIndex, Func <T, Color> getForeColor) where K : class { Items.Clear(); dictItems.Clear(); LoadPartItems <T, K>(items, Items, getId, getParentId, getDisplayName, dictPropertyName, getImageIndex, getForeColor); }
internal void GetCheckedItems(ref TreeListViewItemCollection items) { if(Checked) items.Add(this); foreach(TreeListViewItem item in Items) item.GetCheckedItems(ref items); }