zoukankan      html  css  js  c++  java
  • TreeList 使用(13.2)

    1.拖拽

       1.1 设置属性:this.treeList1.OptionsBehavior.DragNodes = true;

                          this.treeList1.OptionsBehavior.ShowEditorOnMouseUp = true;
                          this.treeList1.OptionsBehavior.CloseEditorOnLostFocus = false;
                          this.treeList1.OptionsBehavior.KeepSelectedOnClick = false;
                          this.treeList1.OptionsBehavior.SmartMouseHover = false;
                          this.treeList1.OptionsSelection.MultiSelect = true;

       1.2 控制拖动是否生效,用 treeList1_DragDrop事件中 e.Effect = DragDropEffects.None;

               //获取当前拖拽的节点

               var dragNode = e.Data.GetData(typeof(TreeListNode)) as TreeListNode;

              //拖拽多个节点

               目前只能拖动一行!!!!!!!!

              //e.keyState取值

     private void treeList1_DragDrop(object sender, DragEventArgs e)
            {
                var dragNode = e.Data.GetData(typeof(TreeListNode)) as TreeListNode;
                var curNode = treeList1.GetDataRecordByNode(dragNode) as DataEntity;
                if (e.KeyState == 8)
                {
    //按ctrl TreeListHitInfo hi
    = treeList1.CalcHitInfo(treeList1.PointToClient(new Point(e.X, e.Y))); if (dragNode != null) { TreeListNode node = hi.Node; if (hi.HitInfoType == HitInfoType.Empty || node != null) { CopyNode(dragNode,node); } } e.Effect = DragDropEffects.None; return; } if (e.KeyState != 8 && !_subjectOperationManager.IsAllowedEditCell(curNode, "ParentID")) { e.Effect = DragDropEffects.None; return; } } private void CopyNode(TreeListNode copyNode, TreeListNode parentNode) {//递归copy子节点 var copyNodeData = treeList1.GetDataRecordByNode(copyNode) as DataEntity; if (copyNode != null) { DataEntitynewNodeData = new DataEntity(); var newNode = treeList1.AppendNode(newNodeData, parentNode.Id); treeList1.MakeNodeVisible(newNode);
    //给新节点绑定数据 ResetNode(newNode, copyNodeData);
    foreach(TreeListNode childNode in copyNode.Nodes) { CopyNode(childNode, newNode); } } }

      1.3 控制拖动鼠标效果:

           private void treeList1_DragOver(object sender, DragEventArgs e)
            {
                TreeListHitInfo hi = treeList1.CalcHitInfo(treeList1.PointToClient(new Point(e.X, e.Y)));
                TreeListNode node = e.Data.GetData(typeof(TreeListNode)) as TreeListNode;
                if (node == null)
                {
                    if (hi.HitInfoType == HitInfoType.Empty || hi.Node != null)
                        e.Effect = DragDropEffects.Copy;
                    else
                        e.Effect = DragDropEffects.None;
                }
            }

    private void ResetNodeData(TreeListNode node,DataEntitynodeData)
            {
                treeList1.BeginUpdate();
                DataEntityoNewNodeData = treeList1.GetDataRecordByNode(node) as DataEntity;
                _subjectOperationManager.CopyValue(nodeData, oNewNodeData);
                treeList1.EndUpdate();
            }

    2.ctrl +拖拽

      2.1 设置属性:this.treeList1.OptionsBehavior.CanCloneNodesOnDrop = true;

      2.2 devExpress V13.2版本的自带的ctrl+拖拽的赋值功能,可以赋值,但修改赋值后的节点数据会喝原先数据一起发生改变。

    3.遍历数据:

      public List<DataEntity> GetTreeData()
            {
                List<DataEntity> lstTreeData = new List<DataEntity>();
                foreach(TreeListNode  node in treeList1.Nodes)
                {
                    GetChieldNodeData(node, lstTreeData);
                }
                return lstTreeData;
            }

            private void GetChieldNodeData(TreeListNode node, List<DataEntity> lstTreeData)
            {
                DataEntitynodeData = treeList1.GetDataRecordByNode(node) as DataEntity;
                lstTreeData.Add(nodeData);
                foreach (TreeListNode childNode in node.Nodes)
                {
                    GetChieldNodeData(childNode, lstTreeData);
                }
                
            }

    4.节点数据编辑:

       添加节点: 只能AppendNode 添加到最后,再通过SetNodeIndex()改变节点位置;

                    treeList1.MoveNode(node, parentNode.ParentNode);
                     treeList1.SetNodeIndex(node, index); 

      列弹出框选择:

                      1. 列的ColumnEditor 选 PopupContainerEdit

                      2. 在界面添加控件 popupContainerControl,在popupContainerControl中添加 treeList

                      3. 绑定: repositoryItemPopupContainerEdit1.PopupControl = popupContainerControl1;

                      4. treeList 双击事件选中数据:

         

    private void treeList3_MouseDoubleClick(object sender, MouseEventArgs e)
            {
                try
                {
                    TreeListHitInfo _hitInfo = treeList3.CalcHitInfo(e.Location);
                    TreeListNode CurrentNode = _hitInfo.Node;
                    if (CurrentNode != null)
                    {
                        DataEntity nodeData = treeList3.GetDataRecordByNode(CurrentNode) as DataEntity ;
                        ResetNode(nodeData);
                        ClosePopup();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

                      5.弹出框的关闭:

                              void ClosePopup()
                  {
                      if (popupContainerControl1.OwnerEdit != null)
                          popupContainerControl1.OwnerEdit.ClosePopup();
                  }

    5. 选中

           不能单元格多选。

    6. 数据筛选:

                treeList1.OptionsFilter.FilterMode = FilterMode.Smart;

         this.treeList1.OptionsBehavior.EnableFiltering = true;

         this.treeList1.OptionsFind.AllowFindPanel = true;
                this.treeList1.OptionsFind.AlwaysVisible = true;
                this.treeList1.OptionsFind.ClearFindOnClose = false; 

  • 相关阅读:
    Codevs 2296 仪仗队 2008年省队选拔赛山东
    Codevs 1535 封锁阳光大学
    Codevs 1069 关押罪犯 2010年NOIP全国联赛提高组
    Codevs 1218 疫情控制 2012年NOIP全国联赛提高组
    Codevs 1684 垃圾陷阱
    洛谷 P1108 低价购买
    Vijos P1325桐桐的糖果计划
    Codevs 3289 花匠 2013年NOIP全国联赛提高组
    Codevs 2611 观光旅游(floyed最小环)
    C语言基础之彩色版C语言(内含linux)
  • 原文地址:https://www.cnblogs.com/benhua/p/6772758.html
Copyright © 2011-2022 走看看