private void RefreshTrafficList() { tvwTraffic.BeginUnboundLoad(); tvwTraffic.Nodes.Clear(); foreach (Itinerary troute in TrafficManager.ActiveItineraries) { // Create the traffic node TreeListNode trafficNode = tvwTraffic.AppendNode(new object[] { troute.ToString() }, null); trafficNode.StateImageIndex = 0; trafficNode.Tag = troute; foreach (Route route in troute.PendingRoutes) { // Create the traffic node TreeListNode routeNode = tvwTraffic.AppendNode(new object[] { route.ToString() }, trafficNode); routeNode.StateImageIndex = (!route.IsActive ? 1 : 2); } trafficNode.Expand(); } tvwTraffic.EndUnboundLoad(); }
private void DropNodes(TreeListNode sourceNode, TreeListNode droppedOnNode) { droppedOnNode.Expand(); var droppedOnCategory = droppedOnNode.Tag as MCategory; var sourceCategory = sourceNode.Tag as MCategory; sourceCategory.Parent = droppedOnCategory; // for a blue icon it will be dropping on the parent of the highlighted node View.ObjectSpace.CommitChanges(); StoreExpandedState(); }
void mnuEditExpandSelection_Click(Object sender, System.EventArgs e) { try { IEnumerator ieItem = tlvKeys.SelectedNodes.GetEnumerator(); while (ieItem.MoveNext()) { TreeListNode tlnItem = (TreeListNode)ieItem.Current; tlnItem.Expand(); } tlvKeys.Refresh(); this.stbStatus.Text = "Selection expanded"; } catch (Exception) {} }
private void CreateTreeViewFromDataSource() { // https://docs.devexpress.com/WindowsForms/DevExpress.XtraTreeList.TreeList // https://docs.devexpress.com/WindowsForms/2434/controls-and-libraries/tree-list // https://docs.devexpress.com/WindowsForms/119635/controls-and-libraries/tree-list/feature-center/data-presentation/treeview-style DevExpress.XtraTreeList.TreeList treeList1 = new DevExpress.XtraTreeList.TreeList() { Dock = WF.DockStyle.Fill }; treeList1.Parent = this; this.Controls.Add(treeList1); // Musí být dřív než se začne pracovat s daty!!! _TreeList = treeList1; //Specify the fields that arrange underlying data as a hierarchy. treeList1.KeyFieldName = "ID"; treeList1.ParentFieldName = "RegionID"; //Allow the treelist to create columns bound to the fields the KeyFieldName and ParentFieldName properties specify. treeList1.OptionsBehavior.PopulateServiceColumns = true; //Specify the data source. treeList1.DataSource = SalesDataGenerator.CreateData(); treeList1.ViewStyle = TreeListViewStyle.TreeView; // treeList1.PopulateColumns(); // treeList1.Refresh(); // treeList1.ForceInitialize(); //The treelist automatically creates columns for the public fields found in the data source. //You do not need to call the TreeList.PopulateColumns method unless the treeList1.OptionsBehavior.AutoPopulateColumns option is disabled. //Change the row height. treeList1.RowHeight = 23; //Access the automatically created columns. TreeListColumn colRegion = treeList1.Columns["Region"]; TreeListColumn colMarchSales = treeList1.Columns["MarchSales"]; TreeListColumn colSeptemberSales = treeList1.Columns["SeptemberSales"]; TreeListColumn colMarchSalesPrev = treeList1.Columns["MarchSalesPrev"]; TreeListColumn colSeptemberSalesPrev = treeList1.Columns["SeptemberSalesPrev"]; TreeListColumn colMarketShare = treeList1.Columns["MarketShare"]; //Hide the key columns. An end-user can access them from the Customization Form. treeList1.Columns[treeList1.KeyFieldName].Visible = false; treeList1.Columns[treeList1.ParentFieldName].Visible = false; //Format column headers and cell values. colMarchSalesPrev.Caption = "<i>Previous <b>March</b> Sales</i>"; colSeptemberSalesPrev.Caption = "<i>Previous <b>September</b> Sales</i>"; treeList1.OptionsView.AllowHtmlDrawHeaders = true; colMarchSalesPrev.AppearanceCell.Font = new System.Drawing.Font(colMarchSalesPrev.AppearanceCell.Font, System.Drawing.FontStyle.Italic); colSeptemberSalesPrev.AppearanceCell.Font = new System.Drawing.Font(colSeptemberSalesPrev.AppearanceCell.Font, System.Drawing.FontStyle.Italic); //Create two hidden unbound columns that calculate their values from expressions. TreeListColumn colUnboundMarchChange = treeList1.Columns.AddField("FromPrevMarchChange"); colUnboundMarchChange.Caption = "Change from prev March"; colUnboundMarchChange.UnboundType = DevExpress.XtraTreeList.Data.UnboundColumnType.Decimal; colUnboundMarchChange.UnboundExpression = "[MarchSales]-[MarchSalesPrev]"; TreeListColumn colUnboundSeptemberChange = treeList1.Columns.AddField("FromPrevSepChange"); colUnboundSeptemberChange.Caption = "Change from prev September"; colUnboundSeptemberChange.UnboundType = DevExpress.XtraTreeList.Data.UnboundColumnType.Decimal; colUnboundSeptemberChange.UnboundExpression = "[SeptemberSales]-[SeptemberSalesPrev]"; colUnboundMarchChange.OptionsColumn.ShowInCustomizationForm = false; colUnboundSeptemberChange.OptionsColumn.ShowInCustomizationForm = false; //Make the Region column read-only. colRegion.OptionsColumn.ReadOnly = true; colRegion.OptionsColumn.AllowEdit = false; colRegion.OptionsColumn.AllowSort = false; colRegion.OptionsColumn.AllowSize = true; //Sort data against the Region column colRegion.SortIndex = 0; //Apply a filter. treeList1.ActiveFilterString = "[MarchSales] > 10000"; treeList1.FocusedNodeChanged += TreeList1_FocusedNodeChanged; //Calculate two total summaries against root nodes. colMarchSales.SummaryFooter = DevExpress.XtraTreeList.SummaryItemType.Sum; colMarchSales.SummaryFooterStrFormat = "Total={0:c0}"; colMarchSales.AllNodesSummary = false; colSeptemberSales.SummaryFooter = DevExpress.XtraTreeList.SummaryItemType.Sum; colSeptemberSales.SummaryFooterStrFormat = "Total={0:c0}"; colSeptemberSales.AllNodesSummary = false; treeList1.OptionsView.ShowSummaryFooter = true; //Use a 'SpinEdit' in-place editor for the *Sales columns. RepositoryItemSpinEdit riSpinEdit = new RepositoryItemSpinEdit(); riSpinEdit.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric; riSpinEdit.DisplayFormat.FormatString = "c0"; treeList1.RepositoryItems.Add(riSpinEdit); colMarchSales.ColumnEdit = riSpinEdit; colMarchSalesPrev.ColumnEdit = riSpinEdit; colSeptemberSales.ColumnEdit = riSpinEdit; colSeptemberSalesPrev.ColumnEdit = riSpinEdit; //Apply Excel-style formatting: display predefined 'Up Arrow' and 'Down Arrow' icons based on the unbound column values. TreeListFormatRule rule1 = new TreeListFormatRule(); rule1.Rule = createThreeTrianglesIconSetRule(); rule1.Column = colUnboundMarchChange; rule1.ColumnApplyTo = colMarchSales; TreeListFormatRule rule2 = new TreeListFormatRule(); rule2.Rule = createThreeTrianglesIconSetRule(); rule2.Column = colUnboundSeptemberChange; rule2.ColumnApplyTo = colSeptemberSales; treeList1.FormatRules.Add(rule1); treeList1.FormatRules.Add(rule2); //Do not stretch columns to the treelist width. treeList1.OptionsView.AutoWidth = false; // Pokud prvek vytvářím v konstruktoru okna, pak musím dát následující řádek, jinak jsou Nodes = prázdné: treeList1.ForceInitialize(); // Když ale konstrukci TreeList provádím v Load eventu, pak to není nutné. //Locate a node by a value it contains. TreeListNode node1 = treeList1.FindNodeByFieldValue("Region", "North America"); //Focus and expand this node. treeList1.FocusedNode = node1; node1.Expanded = true; //Locate a node by its key field value and expand it. TreeListNode node2 = treeList1.FindNodeByKeyID(32);//Node 'Asia' node2.Expand(); // Pokud prvek vytvářím v konstruktoru okna, pak následující řádek nebude chodit = chyba "Není vytvořen popisovač okna": // Když ale konstrukci TreeList provádím v Load eventu, pak následující řádek funguje: // Calculate the optimal column widths after the treelist is shown. // this.BeginInvoke(new WF.MethodInvoker(delegate { treeList1.BestFitColumns(); })); }
private void UpdateOperation(LinkNode node) { OpLink link = node.Link; TreeListNode parent = null; OpLink uplink = GetTreeHigher(link); if (uplink == null) { parent = virtualParent; } else if (NodeMap.ContainsKey(uplink.UserID)) { parent = NodeMap[uplink.UserID]; } else if (uplink.IsLoopRoot) { parent = CreateNode(uplink); LoadRoot((LinkNode)parent); } // else branch this link is apart of is not visible in current display // self is changing ensure it's visible if (node.Link.UserID == Core.UserID) { if (parent == null) { List <ulong> uplinks = Trust.GetUnconfirmedUplinkIDs(Core.UserID, Project); uplinks.Add(Core.UserID); ExpandPath(node, uplinks); // check nodeMap again now that highers added if (NodeMap.ContainsKey(uplink.UserID)) { parent = NodeMap[uplink.UserID]; } } if (parent != null) { parent.Expand(); } } // remember settings bool selected = node.Selected; bool expanded = node.IsExpanded; bool loadsubs = node.AddSubs; // update parent node if (node.Parent != parent) { List <ulong> visible = new List <ulong>(); // remove previous instance of node if (node.Parent != null) { if (node.IsVisible()) { visible.Add(link.UserID); } LinkNode oldParent = node.Parent as LinkNode; LinkNode unload = (oldParent != null && oldParent.Link.IsLoopRoot) ? oldParent : node; // if old parent is a loop node, the loop is made obsolete by change UnloadNode(unload, visible); unload.Remove(); } if (parent == null) { return; } // if new parent is hidden, dont bother adding till user expands LinkNode newParent = parent as LinkNode; // null if virtual parent (root) if (newParent != null && newParent.AddSubs == false) { return; } // copy node to start fresh LinkNode newNode = CreateNode(node.Link); if (newParent != null) { GuiUtils.InsertSubNode(newParent, newNode); } else { LoadRoot(newNode); } ArrangeRoots(); // arrange nodes can cause newNode to become invalid, retrieve updated copy if (!NodeMap.ContainsKey(link.UserID)) { return; } newNode = NodeMap[link.UserID]; if (loadsubs) // if previous node set to add kids { LoadNode(newNode); if (expanded) // if previous node set expanded { newNode.Expand(); } } node = newNode; // recurse to each previously visible node List <LinkNode> roots = new List <LinkNode>(); foreach (TreeListNode treeNode in Nodes) { if (treeNode.GetType() == typeof(LinkNode)) { if (((LinkNode)treeNode).Section == ProjectNode) { roots.Add(treeNode as LinkNode); } } } foreach (ulong id in visible) { List <ulong> uplinks = Trust.GetUnconfirmedUplinkIDs(id, Project); foreach (LinkNode root in roots) { VisiblePath(root, uplinks); } } // show unlinked if there's something to show if (Nodes.IndexOf(UnlinkedNode) + 1 == Nodes.Count) { UnlinkedNode.Text = ""; } else { UnlinkedNode.Text = "Untrusted"; } } node.UpdateStatus(); if (selected) { node.Selected = true; } Invalidate(); }