海纳百川

TreeList(二)

上一篇介绍了TreeListNode节点的三种状态。下面将介绍TreeList的几种比较常用,重要的事件和TreeList的命中测试特性。

1.TreeList.NodeCellStyle事件

Node的显示(包括窗口的切换导致Node的显示)和状态的改变都会触发该事件。该事件主要用来改变Node的显示样式。

 private void treeList1_NodeCellStyle(object sender, DevExpress.XtraTreeList.GetCustomNodeCellStyleEventArgs e)
        {
            if (e.Node.CheckState == CheckState.Unchecked)
            {
                e.Appearance.Font = new Font(DevExpress.Utils.AppearanceObject.DefaultFont, FontStyle.Strikeout);
                e.Appearance.ForeColor = Color.Gray;
            }
        }

上面的代码是实现的效果是 : CheckState为Unchecked的节点的字带有中划线且背景灰色。

 

2.TreeList.DoubleClick事件

双击Node时触发,但要注意的是要在TreeList.OptionsBehavior.Editable = false的情况下,双击Node才能触发该事件。

        private void treeList1_DoubleClick(object sender, EventArgs e)
        {
            TreeListNode clickedNode = this.treeList1.FocusedNode;
            string disPlayText = clickedNode.GetDisplayText("test"); 
            MessageBox.Show("You clicked " + disPlayText);
        }

 

3.TreeList的命中测试特性

 private void treeList1_MouseMove(object sender, MouseEventArgs e)
        {
            Point point = treeList1.PointToClient(Cursor.Position);
            TreeListHitInfo hitInfo = treeList1.CalcHitInfo(point);
            switch (hitInfo.HitInfoType)
            {
                case HitInfoType.Cell:
                    this.Cursor = Cursors.Hand;
                    break;
                case HitInfoType.NodeCheckBox:
                    this.Cursor = Cursors.PanEast;
                    break;
                default :
                    this.Cursor = Cursors.Default;
                    break;
            }
        }

posted on 2010-05-08 22:13  These days  阅读(4683)  评论(2编辑  收藏  举报

导航