protected void ASPxTreeList1_SelectionChanged(object sender, EventArgs e) { ASPxTreeList treeList = sender as ASPxTreeList; if (treeList.SelectionCount == 1) // One node is selected within the control { LastSelectedNode = treeList.GetSelectedNodes()[0].Key; } if (treeList.SelectionCount > 1) // Applies selection to the last selected node, if two nodes are selected { TreeListNode prevSelectedNode = treeList.FindNodeByKeyValue(LastSelectedNode); if (prevSelectedNode != null) { prevSelectedNode.Selected = false; LastSelectedNode = treeList.GetSelectedNodes()[0].Key; } } }
protected void treeList_CustomDataCallback(object sender, DevExpress.Web.ASPxTreeList.TreeListCustomDataCallbackEventArgs e) { ASPxTreeList treeList = (ASPxTreeList)sender; List <TreeListNode> nodelist = treeList.GetSelectedNodes(); //数据压缩 List <ExtendCode> codelist = new List <ExtendCode>(); foreach (TreeListNode node in nodelist) { ExtendCode detail = (ExtendCode)node.DataItem; codelist.Add(detail); } e.Result = JsonConvert.SerializeObject(codelist); }
protected void treeInventory_SelectionChanged(object sender, EventArgs e) { ASPxTreeList treeList = sender as ASPxTreeList; Session["InventorySelected"] = treeList.GetSelectedNodes()[0].Key; }
private void NavigatorsUpdateRemoveTrees(object fromTreeVal, object toTreeVal) { ASPxTreeList fromTree = (ASPxTreeList)fromTreeVal; ASPxTreeList toTree = (ASPxTreeList)toTreeVal; DataTable dataFrom = new DataTable(); string[] fieldValues = new string[5]; List <string> fieldValuesID = new List <string>(); List <string> fieldValuesDisplayText = new List <string>(); List <string> fieldValuesOrderNum = new List <string>(); List <string> fieldValuesParentID = new List <string>(); List <string> fieldValuesPageLink = new List <string>(); List <TreeListNode> selectItemsNavID = fromTree.GetSelectedNodes(); foreach (TreeListNode selectItemNavID in selectItemsNavID) { //If selected node is not already in the list, add it to the list if (fieldValuesID != null) { if (!fieldValuesID.Contains(selectItemNavID.GetValue("ID").ToString())) { fieldValuesID.Add(selectItemNavID.GetValue("ID").ToString()); fieldValuesDisplayText.Add(selectItemNavID.GetValue("DisplayText").ToString()); fieldValuesOrderNum.Add(selectItemNavID.GetValue("OrderNum").ToString()); fieldValuesParentID.Add(selectItemNavID.GetValue("ParentID").ToString()); fieldValuesPageLink.Add(selectItemNavID.GetValue("PageLink").ToString()); } } } //Build data table based on the existing nodes in the tree dataFrom = NavigatorBuildDataTable(fromTree); dataFrom.PrimaryKey = new DataColumn[] { dataFrom.Columns["ID"] }; DataRow dr; //Remove values from the data table, then re-assign the data table to the navigator for (int i = 0; i < fieldValuesID.Count; i++) { fieldValues[0] = fieldValuesID[i]; fieldValues[1] = fieldValuesDisplayText[i]; fieldValues[2] = fieldValuesOrderNum[i];; fieldValues[3] = fieldValuesParentID[i]; fieldValues[4] = fieldValuesPageLink[i]; if (dataFrom.Rows.Contains(fieldValues[0])) { if (fieldValues[3] != "") { DataRow[] foundRows = dataFrom.Select("ParentID = '" + fieldValues[3].ToString() + "'", "ParentID ASC", DataViewRowState.Added); if (foundRows.Length == 1) { //DataTable dtmenus = foundRows.CopyToDataTable(); //foreach (DataRow row in dtmenus.Rows) //{ // dr = dataFrom.Rows.Find(row[0].ToString()); // dataFrom.Rows.Remove(dr); //} dr = dataFrom.Rows.Find(fieldValues[3]); if (dr != null) { dataFrom.Rows.Remove(dr); } } } dr = dataFrom.Rows.Find(fieldValues[0]); dataFrom.Rows.Remove(dr); } } Session["DataNotVisible"] = dataFrom; /* * IEnumerable<TreeListNode> list = fromTree.GetAllNodes(); * foreach (TreeListNode node in list) * { * int ind = fieldValuesID.IndexOf(node.GetValue("ID").ToString()); * if (ind == -1) * { * fieldValues[0] = node.GetValue("ID").ToString(); * fieldValues[1] = node.GetValue("DisplayText").ToString(); * fieldValues[2] = node.GetValue("OrderNum").ToString(); * fieldValues[3] = node.GetValue("ParentID").ToString(); * fieldValues[4] = node.GetValue("PageLink").ToString(); * dataFrom.Rows.Add(fieldValues); * } * } * fromTree.DataSource = dataFrom; * fromTree.KeyFieldName = "ID"; * fromTree.ParentFieldName = "ParentID"; * fromTree.DataBind(); */ fromTree.UnselectAll(); fromTree.DataSource = dataFrom; fromTree.KeyFieldName = "ID"; fromTree.ParentFieldName = "ParentID"; fromTree.DataBind(); }
private void NavigatorsRebuildTrees(object fromTreeVal, object toTreeVal) { ASPxTreeList fromTree = (ASPxTreeList)fromTreeVal; ASPxTreeList toTree = (ASPxTreeList)toTreeVal; DataTable dataTo = new DataTable(); string[] fieldValues = new string[5]; List <string> fieldValuesID = new List <string>(); List <string> fieldValuesDisplayText = new List <string>(); List <string> fieldValuesOrderNum = new List <string>(); List <string> fieldValuesParentID = new List <string>(); List <string> fieldValuesPageLink = new List <string>(); List <TreeListNode> selectItemsNavID = fromTree.GetSelectedNodes(); foreach (TreeListNode selectItemNavID in selectItemsNavID) { //Check if a selected node has a parent if (selectItemNavID.ParentNode != null && selectItemNavID.ParentNode.Key != "") { //If the parent node is not already in the list, add it to the list //if (fieldValuesID != null) //{ // if (!fieldValuesID.Contains(selectItemNavID.ParentNode.GetValue("ID").ToString())) // { // fieldValuesID.Add(selectItemNavID.ParentNode.GetValue("ID").ToString()); // fieldValuesDisplayText.Add(selectItemNavID.ParentNode.GetValue("DisplayText").ToString()); // fieldValuesOrderNum.Add(selectItemNavID.ParentNode.GetValue("OrderNum").ToString()); // fieldValuesParentID.Add(selectItemNavID.ParentNode.GetValue("ParentID").ToString()); // fieldValuesPageLink.Add(selectItemNavID.ParentNode.GetValue("PageLink").ToString()); // } //} } //If selected node is not already in the list, add it to the list if (fieldValuesID != null) { if (!fieldValuesID.Contains(selectItemNavID.GetValue("ID").ToString())) { fieldValuesID.Add(selectItemNavID.GetValue("ID").ToString()); fieldValuesDisplayText.Add(selectItemNavID.GetValue("DisplayText").ToString()); fieldValuesOrderNum.Add(selectItemNavID.GetValue("OrderNum").ToString()); fieldValuesParentID.Add(selectItemNavID.GetValue("ParentID").ToString()); fieldValuesPageLink.Add(selectItemNavID.GetValue("PageLink").ToString()); } } } //Build data table based on the existing nodes in the tree dataTo = NavigatorBuildDataTable(toTree); dataTo.PrimaryKey = new DataColumn[] { dataTo.Columns["ID"] }; //Add new values to the data table, then re-assign the data table to the navigator for (int i = 0; i < fieldValuesID.Count; i++) { fieldValues[0] = fieldValuesID[i]; fieldValues[1] = fieldValuesDisplayText[i]; fieldValues[2] = fieldValuesOrderNum[i];; fieldValues[3] = fieldValuesParentID[i]; fieldValues[4] = fieldValuesPageLink[i]; if (!dataTo.Rows.Contains(fieldValues[0])) { dataTo.Rows.Add(fieldValues); } } Session["DataNotVisible"] = dataTo; /* * IEnumerable<TreeListNode> list = fromTree.GetAllNodes(); * foreach (TreeListNode node in list) * { * int ind = fieldValuesID.IndexOf(node.GetValue("ID").ToString()); * if (ind == -1) * { * fieldValues[0] = node.GetValue("ID").ToString(); * fieldValues[1] = node.GetValue("DisplayText").ToString(); * fieldValues[2] = node.GetValue("OrderNum").ToString(); * fieldValues[3] = node.GetValue("ParentID").ToString(); * fieldValues[4] = node.GetValue("PageLink").ToString(); * dataFrom.Rows.Add(fieldValues); * } * } * fromTree.DataSource = dataFrom; * fromTree.KeyFieldName = "ID"; * fromTree.ParentFieldName = "ParentID"; * fromTree.DataBind(); */ //fromTree.UnselectAll(); NavigatorVisibleTreeList.UnselectAll(); toTree.DataSource = dataTo; toTree.KeyFieldName = "ID"; toTree.ParentFieldName = "ParentID"; toTree.DataBind(); }