public int IndexOf(TreeListNode item) { return List.IndexOf(item); }
public void Remove(TreeListNode item) { List.Remove(item); }
public int Add(TreeListNode item) { item.MouseDown += new MouseEventHandler(OnMouseDown); item.Nodes.NodesChanged += new EventHandler(OnNodesChanged); item.Parent = owner; OnNodesChanged(); return item.Index = List.Add(item); }
public void AddRange(TreeListNode[] items) { lock(List.SyncRoot) { for (int i=0; i<items.Length; i++) { items[i].MouseDown += new MouseEventHandler(OnMouseDown); items[i].Nodes.NodesChanged+= new EventHandler(OnNodesChanged); items[i].Parent = owner; items[i].Index = List.Add(items[i]); } OnNodesChanged(); } }
private TreeListNodeCollection GetSelectedNodes(TreeListNode node) { TreeListNodeCollection list = new TreeListNodeCollection(); for (int i=0; i<node.Nodes.Count; i++) { // check if current node is selected if (node.Nodes[i].Selected) { list.Add(node.Nodes[i]); } // chech if node is expanded and has // selected children if (node.Nodes[i].IsExpanded) { TreeListNodeCollection list2 = GetSelectedNodes(node.Nodes[i]); for (int j=0; j<list2.Count; j++) { list.Add(list2[i]); } } } return list; }
public int this[TreeListNode item] { get { return List.IndexOf(item); } }
public object PreviousChild() { curChild = (TreeListNode)curChild.PreviousSibling(); return curChild; }
public override bool PreProcessMessage(ref Message msg) { if (msg.Msg == WM_KEYDOWN) { if (nodes.Count > 0) { if (curNode != null) { Keys keyData = ((Keys) (int) msg.WParam) | ModifierKeys; Keys keyCode = ((Keys) (int) msg.WParam); if (keyCode == Keys.Left) // collapse current node or move up to parent { if (curNode.IsExpanded) { curNode.Collapse(); } else if (curNode.ParentNode() != null) { TreeListNode t = (TreeListNode)curNode.ParentNode(); if (t.ParentNode() != null) // never select virtualParent node { if (!multiSelect) curNode.Selected = false; //else curNode.Focused = false; curNode = (TreeListNode)curNode.ParentNode(); if (!multiSelect) curNode.Selected = true; //else curNode.Focused = true; } } Invalidate(); return true; } else if (keyCode == Keys.Right) // expand current node or move down to first child { if (!curNode.IsExpanded) { curNode.Expand(); } else if (curNode.IsExpanded && curNode.GetNodeCount(false) > 0) { if (!multiSelect) curNode.Selected = false; //else curNode.Focused = false; curNode = (TreeListNode)curNode.FirstChild(); if (!multiSelect) curNode.Selected = true; //else curNode.Focused = true; } Invalidate(); return true; } else if (keyCode == Keys.Up) { if (curNode.PreviousSibling() == null && curNode.ParentNode() != null) { TreeListNode t = (TreeListNode)curNode.ParentNode(); if (t.ParentNode() != null) // never select virtualParent node { if (!multiSelect) curNode.Selected = false; //else curNode.Focused = false; curNode = (TreeListNode)curNode.ParentNode(); if (!multiSelect) curNode.Selected = true; //else curNode.Focused = true; } Invalidate(); return true; } else if (curNode.PreviousSibling() != null) { TreeListNode t = (TreeListNode)curNode.PreviousSibling(); if (t.GetNodeCount(false) > 0 && t.IsExpanded) { do { t = (TreeListNode)t.LastChild(); if (!t.IsExpanded) { if (!multiSelect) curNode.Selected = false; //else curNode.Focused = false; curNode = t; if (!multiSelect) curNode.Selected = true; //else curNode.Focused = true; } } while (t.GetNodeCount(false) > 0 && t.IsExpanded); } else { if (!multiSelect) curNode.Selected = false; //else curNode.Focused = false; curNode = (TreeListNode)curNode.PreviousSibling(); if (!multiSelect) curNode.Selected = true; //else curNode.Focused = true; } Invalidate(); return true; } } else if (keyCode == Keys.Down) { if (curNode.IsExpanded && curNode.GetNodeCount(false) > 0) { if (!multiSelect) curNode.Selected = false; //else curNode.Focused = false; curNode = (TreeListNode)curNode.FirstChild(); if (!multiSelect) curNode.Selected = true; //else curNode.Focused = true; } else if (curNode.NextSibling() == null && curNode.ParentNode() != null) { TreeListNode t = curNode; do { t = (TreeListNode)t.ParentNode(); if (t.NextSibling() != null) { if (!multiSelect) curNode.Selected = false; //else curNode.Focused = false; curNode = (TreeListNode)t.NextSibling(); if (!multiSelect) curNode.Selected = true; //else curNode.Focused = true; break; } } while (t.NextSibling() == null && t.ParentNode() != null); } else if (curNode.NextSibling() != null) { if (!multiSelect) curNode.Selected = false; //else curNode.Focused = false; curNode = (TreeListNode)curNode.NextSibling(); if (!multiSelect) curNode.Selected = true; //else curNode.Focused = true; } Invalidate(); return true; } } } } return base.PreProcessMessage(ref msg); }
public object LastChild() { curChild = Nodes[Nodes.Count-1]; return curChild; }
public object NextChild() { curChild = (TreeListNode)curChild.NextSibling(); return curChild; }
public object FirstChild() { curChild = Nodes[0]; return curChild; }
private void RenderPlus(Graphics g, int x, int y, int w, int h, TreeListNode node) { if (VisualStyles) { if (node.IsExpanded) g.DrawImage(bmpMinus, x, y); else g.DrawImage(bmpPlus, x, y); } else { g.DrawRectangle(new Pen(SystemBrushes.ControlDark),x, y, w, h); g.FillRectangle(new SolidBrush(Color.White), x+1, y+1, w-1, h-1); g.DrawLine(new Pen(new SolidBrush(Color.Black)), x+2, y+4, x+w-2, y+4); if (!node.IsExpanded) g.DrawLine(new Pen(new SolidBrush(Color.Black)), x+4, y+2, x+4, y+h-2); } pmRects.Add(new Rectangle(x, y, w, h), node); }
private void RenderNodeRows(TreeListNode node, Graphics g, Rectangle r, int level, int index, ref int totalRend, ref int childCount, int count) { if (node.IsVisible) { int eb = 10; // edge buffer // only render if row is visible in viewport if (((r.Top+itemheight*totalRend+eb/4-vscrollBar.Value+itemheight > r.Top) && (r.Top+itemheight*totalRend+eb/4-vscrollBar.Value < r.Top+r.Height))) { rendcnt++; int lb = 0; // level buffer int ib = 0; // icon buffer int hb = headerBuffer; // header buffer Pen linePen = new Pen(SystemBrushes.ControlDark, 1.0f); Pen PMPen = new Pen(SystemBrushes.ControlDark, 1.0f); Pen PMPen2 = new Pen(new SolidBrush(Color.Black), 1.0f); linePen.DashStyle = DashStyle.Solid; // add space for plis/minus icons and/or root lines to the edge buffer if (showrootlines || showplusminus) { eb += 10; } // set level buffer lb = indent*level; // set icon buffer if ((node.Selected || node.Focused) && stateImageList != null) { if (node.ImageIndex >= 0 && node.ImageIndex < stateImageList.Images.Count) { stateImageList.Draw(g, r.Left+lb+eb+2-hscrollBar.Value, r.Top+hb+itemheight*totalRend+eb/4-2-vscrollBar.Value, 16, 16, node.ImageIndex); ib = 18; } } else { if (smallImageList != null && node.ImageIndex >= 0 && node.ImageIndex < smallImageList.Images.Count) { smallImageList.Draw(g, r.Left+lb+eb+2-hscrollBar.Value, r.Top+hb+itemheight*totalRend+eb/4-2-vscrollBar.Value, 16, 16, node.ImageIndex); ib = 18; } } // add a rectangle to the node row rectangles Rectangle sr = new Rectangle(r.Left+lb+ib+eb+4-hscrollBar.Value, r.Top+hb+itemheight*totalRend+2-vscrollBar.Value, allColsWidth-(lb+ib+eb+4), itemheight); nodeRowRects.Add(sr, node); // render per-item background if (node.BackColor != this.BackColor) { if (node.UseItemStyleForSubItems) g.FillRectangle(new SolidBrush(node.BackColor), r.Left+lb+ib+eb+4-hscrollBar.Value, r.Top+hb+itemheight*totalRend+2-vscrollBar.Value, allColsWidth-(lb+ib+eb+4), itemheight); else g.FillRectangle(new SolidBrush(node.BackColor), r.Left+lb+ib+eb+4-hscrollBar.Value, r.Top+hb+itemheight*totalRend+2-vscrollBar.Value, columns[0].Width-(lb+ib+eb+4), itemheight); } g.Clip = new Region(sr); // render selection and focus if (node.Selected && isFocused) { g.FillRectangle(new SolidBrush(rowSelectColor), sr); } else if (node.Selected && !isFocused && !hideSelection) { g.FillRectangle(SystemBrushes.Control, sr); } else if (node.Selected && !isFocused && hideSelection) { ControlPaint.DrawFocusRectangle(g, sr); } if (node.Focused && ((isFocused && multiSelect) || !node.Selected)) { ControlPaint.DrawFocusRectangle(g, sr); } g.Clip = new Region(new Rectangle(r.Left+2-hscrollBar.Value, r.Top+hb+2, columns[0].Width, r.Height-hb-4)); // render root lines if visible if (r.Left+eb-hscrollBar.Value > r.Left) { if (showrootlines && level == 0) { if (index == 0) { g.DrawLine(linePen, r.Left+eb/2-hscrollBar.Value, r.Top+eb/2+hb-vscrollBar.Value, r.Left+eb-hscrollBar.Value, r.Top+eb/2+hb-vscrollBar.Value); g.DrawLine(linePen, r.Left+eb/2-hscrollBar.Value, r.Top+eb/2+hb-vscrollBar.Value, r.Left+eb/2-hscrollBar.Value, r.Top+eb+hb-vscrollBar.Value); } else if (index == count-1) { g.DrawLine(linePen, r.Left+eb/2-hscrollBar.Value, r.Top+eb/2+hb+itemheight*(totalRend)-vscrollBar.Value, r.Left+eb-hscrollBar.Value, r.Top+eb/2+hb+itemheight*(totalRend)-vscrollBar.Value); g.DrawLine(linePen, r.Left+eb/2-hscrollBar.Value, r.Top+hb+itemheight*(totalRend)-vscrollBar.Value, r.Left+eb/2-hscrollBar.Value, r.Top+eb/2+hb+itemheight*(totalRend)-vscrollBar.Value); } else { g.DrawLine(linePen, r.Left+eb/2-hscrollBar.Value, r.Top+eb+hb+itemheight*(totalRend)-eb/2-vscrollBar.Value, r.Left+eb-hscrollBar.Value, r.Top+eb+hb+itemheight*(totalRend)-eb/2-vscrollBar.Value); g.DrawLine(linePen, r.Left+eb/2-hscrollBar.Value, r.Top+eb+hb+itemheight*(totalRend-1)-vscrollBar.Value, r.Left+eb/2-hscrollBar.Value, r.Top+eb+hb+itemheight*(totalRend)-vscrollBar.Value); } if (childCount > 0) g.DrawLine(linePen, r.Left+eb/2-hscrollBar.Value, r.Top+hb+itemheight*(totalRend-childCount)-vscrollBar.Value, r.Left+eb/2-hscrollBar.Value, r.Top+hb+itemheight*(totalRend)-vscrollBar.Value); } } // render child lines if visible if (r.Left+lb+eb-hscrollBar.Value > r.Left) { if (showlines && level > 0) { if (index == count-1) { g.DrawLine(linePen, r.Left+lb+eb/2-hscrollBar.Value, r.Top+eb/2+hb+itemheight*(totalRend)-vscrollBar.Value, r.Left+lb+eb-hscrollBar.Value, r.Top+eb/2+hb+itemheight*(totalRend)-vscrollBar.Value); g.DrawLine(linePen, r.Left+lb+eb/2-hscrollBar.Value, r.Top+hb+itemheight*(totalRend)-vscrollBar.Value, r.Left+lb+eb/2-hscrollBar.Value, r.Top+eb/2+hb+itemheight*(totalRend)-vscrollBar.Value); } else { g.DrawLine(linePen, r.Left+lb+eb/2-hscrollBar.Value, r.Top+eb/2+hb+itemheight*(totalRend)-vscrollBar.Value, r.Left+lb+eb-hscrollBar.Value, r.Top+eb/2+hb+itemheight*(totalRend)-vscrollBar.Value); g.DrawLine(linePen, r.Left+lb+eb/2-hscrollBar.Value, r.Top+hb+itemheight*(totalRend)-vscrollBar.Value, r.Left+lb+eb/2-hscrollBar.Value, r.Top+eb+hb+itemheight*(totalRend)-vscrollBar.Value); } if (childCount > 0) g.DrawLine(linePen, r.Left+lb+eb/2-hscrollBar.Value, r.Top+hb+itemheight*(totalRend-childCount)-vscrollBar.Value, r.Left+lb+eb/2-hscrollBar.Value, r.Top+hb+itemheight*(totalRend)-vscrollBar.Value); } } // render +/- signs if visible if (r.Left+lb+eb/2+5-hscrollBar.Value > r.Left) { if (showplusminus && (node.GetNodeCount(false) > 0 || alwaysShowPM)) { if (index == 0 && level == 0) { RenderPlus(g, r.Left+lb+eb/2-4-hscrollBar.Value, r.Top+hb+eb/2-4-vscrollBar.Value, 8, 8, node); } else if (index == count-1) { RenderPlus(g, r.Left+lb+eb/2-4-hscrollBar.Value, r.Top+hb+itemheight*totalRend+eb/2-4-vscrollBar.Value, 8, 8, node); } else { RenderPlus(g, r.Left+lb+eb/2-4-hscrollBar.Value, r.Top+hb+itemheight*totalRend+eb/2-4-vscrollBar.Value, 8, 8, node); } } } // render text if visible if (r.Left+columns[0].Width-hscrollBar.Value > r.Left) { if (node.Selected && isFocused) g.DrawString(TruncatedString(node.Text, columns[0].Width, lb+eb+ib+6, g), Font, SystemBrushes.HighlightText, (float)(r.Left+lb+ib+eb+4-hscrollBar.Value), (float)(r.Top+hb+itemheight*totalRend+eb/4-vscrollBar.Value)); else g.DrawString(TruncatedString(node.Text, columns[0].Width, lb+eb+ib+6, g), Font, new SolidBrush(node.ForeColor), (float)(r.Left+lb+ib+eb+4-hscrollBar.Value), (float)(r.Top+hb+itemheight*totalRend+eb/4-vscrollBar.Value)); } // render subitems int j; int last = 0; if (columns.Count > 0) { for (j=0; j<node.SubItems.Count && j<columns.Count; j++) { last += columns[j].Width; g.Clip = new Region(new Rectangle(last+6-hscrollBar.Value, r.Top+headerBuffer+2, (last+columns[j+1].Width > r.Width-6 ? r.Width-6 : columns[j+1].Width-6), r.Height-5)); if (node.SubItems[j].ItemControl != null) { Control c = node.SubItems[j].ItemControl; c.Location = new Point(r.Left+last+4-hscrollBar.Value, r.Top+(itemheight*totalRend)+headerBuffer+4-vscrollBar.Value); c.ClientSize = new Size(columns[j+1].Width-6, rowHeight-4); c.Parent = this; } else { string sp = ""; if (columns[j+1].TextAlign == HorizontalAlignment.Left) { if (node.Selected && isFocused) g.DrawString(TruncatedString(node.SubItems[j].Text, columns[j+1].Width, 9, g), this.Font, SystemBrushes.HighlightText, (float)(last+6-hscrollBar.Value), (float)(r.Top+(itemheight*totalRend)+headerBuffer+4-vscrollBar.Value)); else g.DrawString(TruncatedString(node.SubItems[j].Text, columns[j+1].Width, 9, g), this.Font, (node.UseItemStyleForSubItems ? new SolidBrush(node.ForeColor) : SystemBrushes.WindowText), (float)(last+6-hscrollBar.Value), (float)(r.Top+(itemheight*totalRend)+headerBuffer+4-vscrollBar.Value)); } else if (columns[j+1].TextAlign == HorizontalAlignment.Right) { sp = TruncatedString(node.SubItems[j].Text, columns[j+1].Width, 9, g); if (node.Selected && isFocused) g.DrawString(sp, this.Font, SystemBrushes.HighlightText, (float)(last+columns[j+1].Width-Helpers.StringTools.MeasureDisplayStringWidth(g, sp, this.Font)-4-hscrollBar.Value), (float)(r.Top+(itemheight*totalRend)+headerBuffer+4-vscrollBar.Value)); else g.DrawString(sp, this.Font, (node.UseItemStyleForSubItems ? new SolidBrush(node.ForeColor) : SystemBrushes.WindowText), (float)(last+columns[j+1].Width-Helpers.StringTools.MeasureDisplayStringWidth(g, sp, this.Font)-4-hscrollBar.Value), (float)(r.Top+(itemheight*totalRend)+headerBuffer+4-vscrollBar.Value)); } else { sp = TruncatedString(node.SubItems[j].Text, columns[j+1].Width, 9, g); if (node.Selected && isFocused) g.DrawString(sp, this.Font, SystemBrushes.HighlightText, (float)(last+(columns[j+1].Width/2)-(Helpers.StringTools.MeasureDisplayStringWidth(g, sp, this.Font)/2)-hscrollBar.Value), (float)(r.Top+(itemheight*totalRend)+headerBuffer+4-vscrollBar.Value)); else g.DrawString(sp, this.Font, (node.UseItemStyleForSubItems ? new SolidBrush(node.ForeColor) : SystemBrushes.WindowText), (float)(last+(columns[j+1].Width/2)-(Helpers.StringTools.MeasureDisplayStringWidth(g, sp, this.Font)/2)-hscrollBar.Value), (float)(r.Top+(itemheight*totalRend)+headerBuffer+4-vscrollBar.Value)); } } } } } // increment number of rendered nodes totalRend++; // render child nodes if (node.IsExpanded) { childCount = 0; for (int n=0; n<node.GetNodeCount(false); n++) { RenderNodeRows(node.Nodes[n], g, r, level+1, n, ref totalRend, ref childCount, node.Nodes.Count); } } childCount = node.GetVisibleNodeCount(true); } else { childCount = 0; } }
public TreeListView() : base() { virtualParent = new TreeListNode(); nodes = virtualParent.Nodes; nodes.Owner = virtualParent; nodes.MouseDown += new MouseEventHandler(OnSubControlMouseDown); nodes.NodesChanged += new EventHandler(OnNodesChanged); selectedNodes = new TreeListNodeCollection(); nodeRowRects = new ListDictionary(); pmRects = new ListDictionary(); // Use reflection to load the // embedded bitmaps for the // styles plus and minus icons Assembly myAssembly = Assembly.GetAssembly(Type.GetType("ExtendedListView.Forms.TreeListView")); Stream bitmapStream1 = myAssembly.GetManifestResourceStream("ExtendedListView.Forms.Resources.tv_minus.bmp"); bmpMinus = new Bitmap(bitmapStream1); Stream bitmapStream2 = myAssembly.GetManifestResourceStream("ExtendedListView.Forms.Resources.tv_plus.bmp"); bmpPlus = new Bitmap(bitmapStream2); }
public void Remove() { int c = nodes.IndexOf(curChild); nodes.Remove(curChild); if (nodes.Count > 0 && nodes.Count > c) curChild = nodes[c]; else curChild = nodes[nodes.Count]; }
public int GetNodeCount(TreeListNode node) { int c = 0; c += node.Nodes.Count; foreach (TreeListNode n in node.Nodes) { c += GetNodeCount(n); } return c; }
public TreeListNodeCollection(TreeListNode owner) { this.owner = owner; }
void DisplaySystemDetails() { _logger.Info("Displaying system details"); if (objDataTable == null || objDataTable["System"] == null) { SetProgressBarState(false); return; } ArrayList tempArray = (ArrayList)objDataTable["System"]; if ( tempArray.Count <= 0) { SetProgressBarState(false); return; } TreeListNode mainParentNode = null; foreach (object entity in tempArray) { bool bNodeAlreadyAdded = true; string _name = SplitCamelCase(entity.GetType().GetProperty("ClassName") .GetValue(entity, null).ToString()); int imageIndex = (int)entity.GetType().GetProperty("Icon").GetValue(entity, null); foreach (TreeListNode tempParentNode in lstDisplayInfo.Nodes) { if (tempParentNode.Text == _name) { mainParentNode = tempParentNode; bNodeAlreadyAdded = false; break; } } if (mainParentNode == null) { mainParentNode = new TreeListNode(); mainParentNode.Text = _name; mainParentNode.ImageIndex = imageIndex; bNodeAlreadyAdded = true; } TreeListNode tln = new TreeListNode(); tln.Text = entity.GetType().GetProperty("NodeName") .GetValue(entity, null).ToString(); tln.ImageIndex = imageIndex; Type t = entity.GetType(); PropertyInfo[] pi = t.GetProperties(); foreach (PropertyInfo prop in pi) { if (prop.Name == "ClassName" || prop.Name == "ScanID" || prop.Name == "Icon" || prop.Name == "NodeName") continue; TreeListNode sub = new TreeListNode(); string subNodeName = prop.Name; if ( subNodeName.Contains("_") == true) { subNodeName = subNodeName.Remove(subNodeName.Length - 2); } sub.Text = SplitCamelCase(subNodeName); if (prop.GetValue(entity, null).GetType().Name == "DateTime" && DateTime.MinValue == (DateTime)prop.GetValue(entity, null)) sub.SubItems.Add(""); else { sub.SubItems.Add(GetPropValue(prop, entity)); } sub.ImageIndex = -1; tln.Nodes.Add(sub); sub = null; } mainParentNode.Nodes.Add(tln); tln = null; if (bNodeAlreadyAdded == true) lstDisplayInfo.Nodes.Add(mainParentNode); mainParentNode = null; } if (cbListExpand.Checked == true) lstDisplayInfo.ExpandAll(); lstDisplayInfo.Invalidate(); SetProgressBarState(false); tempArray.Clear(); tempArray = null; }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); for (int i=0; i<columns.Count; i++) { if (columnSizeRects.Length > 0 && MouseInRect(e, columnSizeRects[i])) { // autosize column if (e.Clicks == 2 && e.Button == MouseButtons.Left) { int mwid = 0; int twid = 0; AutoSetColWidth(nodes, ref mwid, ref twid, i); twid = GetStringWidth(columns[i].Text); if (twid > mwid) mwid = twid; mwid += 5; if (columns[i].Image != null) mwid += 18; columns[i].Width = mwid; GenerateColumnRects(); } // scale column else { colScaleMode = true; colScaleWid = columnRects[i].Width; scaledCol = i; } } } if (MouseInRect(e, rowsRect)) { TreeListNode cnode; // check if a nodes plus/minus has been clicked cnode = NodePlusClicked(e); if (cnode != null) { cnode.Toggle(); AdjustScrollbars(); Invalidate(ClientRectangle); return; } if (e.Button == MouseButtons.Left) { // check if a noderow has been clicked if (multiSelectMode == MultiSelectMode.Single) { UnselectNodes(nodes); //selectedNodes.Clear(); cnode = NodeInNodeRow(e); if (cnode != null) { cnode.Focused = true; cnode.Selected = true; curNode = cnode; //selectedNodes.Add(curNode); if (e.Clicks == 2 && !mouseActivate) { cnode.Toggle(); AdjustScrollbars(); } else if (e.Clicks == 2 && mouseActivate) OnItemActivate(new EventArgs()); } else if (curNode != null) { curNode.Focused = false; curNode.Selected = false; } Invalidate(); } else if (multiSelectMode == MultiSelectMode.Range) { // to be implemented at a later date } else if (multiSelectMode == MultiSelectMode.Selective) { UnfocusNodes(nodes); cnode = NodeInNodeRow(e); if (cnode != null) { if (cnode.Selected) { // remove node from collection of selected nodes //selectedNodes.Remove(curNode); cnode.Focused = false; cnode.Selected = false; curNode = null; } else { cnode.Focused = true; cnode.Selected = true; curNode = cnode; // add node to collection of selected nodes //selectedNodes.Add(curNode); } if (e.Clicks == 2 && !mouseActivate) { cnode.Toggle(); AdjustScrollbars(); } else if (e.Clicks == 2 && mouseActivate) OnItemActivate(new EventArgs()); Invalidate(); } } } } }