Ejemplo n.º 1
0
 /// <summary>
 /// 显示行号
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void treeList1_CustomDrawNodeIndicator(object sender, CustomDrawNodeIndicatorEventArgs e)
 {
     DevExpress.XtraTreeList.TreeList tmpTree = sender as DevExpress.XtraTreeList.TreeList;
     DevExpress.Utils.Drawing.IndicatorObjectInfoArgs args = e.ObjectArgs as DevExpress.Utils.Drawing.IndicatorObjectInfoArgs;
     if (args != null)
     {
         int rowNum = tmpTree.GetVisibleIndexByNode(e.Node) + 1;
         args.DisplayText = rowNum.ToString();
     }
     e.ImageIndex = -1;
 }
Ejemplo n.º 2
0
        public static void SetITLTreeListStyle(TreeList treeList, Function <string> GetEmptyDisplayInfo = null)
        {
            treeList.OptionsMenu.EnableColumnMenu = false;                                                //禁用许列头上的菜单
            treeList.OptionsMenu.EnableFooterMenu = false;                                                //禁用允许页脚上的菜单

            treeList.OptionsBehavior.AllowRecursiveNodeChecking = true;                                   //父节点的选中状态影响其子节点的选中状态
            treeList.OptionsBehavior.Editable = false;                                                    //设置不可编辑
            treeList.OptionsSelection.EnableAppearanceFocusedCell = false;                                //焦点单元格不受外观控制
            treeList.OptionsSelection.InvertSelection             = false;                                //设置焦点的风格应用到获得焦点的单元格,还是获得焦点的那一行的所有单元格\
            treeList.OptionsView.ShowColumns         = true;                                              //显示列标题
            treeList.OptionsView.ShowFilterPanelMode = DevExpress.XtraTreeList.ShowFilterPanelMode.Never; //底部区域
            treeList.OptionsView.ShowIndicator       = false;                                             //不显示行指示器
                                                                                                          //treeList.OptionsView.ShowRoot = false;  //不显示根节点


            treeList.VertScrollVisibility = DevExpress.XtraTreeList.ScrollVisibility.Auto;                                 //自动显示垂直滚动条
            treeList.OptionsView.EnableAppearanceEvenRow    = true;                                                        //奇数行使用外观
            treeList.OptionsView.EnableAppearanceOddRow     = true;                                                        //偶数行使用外观
            treeList.OptionsView.FocusRectStyle             = DevExpress.XtraTreeList.DrawFocusRectStyle.None;             //焦点样式
            treeList.OptionsView.HeaderFilterButtonShowMode = DevExpress.XtraEditors.Controls.FilterButtonShowMode.Button; //列标题排序按钮样式
            treeList.OptionsView.ShowHorzLines = true;                                                                     //显示水平线
            treeList.OptionsView.ShowVertLines = true;                                                                     //显示垂直线

            treeList.OptionsView.ColumnHeaderAutoHeight = DevExpress.Utils.DefaultBoolean.True;                            //列标题自适应高度,设置后无行指示器
            treeList.OptionsView.AutoWidth = true;                                                                         //允许自动调整列宽
            //treeList.Appearance.Empty.BackColor = ControlUtilityTool.PubBackColorNormal;  //空白处背景色
            treeList.Appearance.OddRow.BackColor  = ControlUtilityTool.PubTableBackColorBlue;                              //偶数行背景色
            treeList.Appearance.EvenRow.BackColor = ControlUtilityTool.PubTableBackColorWhite;                             //奇数行背景色
            treeList.CustomDrawNodeIndicator     += (sender, e) =>                                                         //绘制行指示器(treeList.OptionsView.ShowIndicator = true时有效)
            {
                TreeList tmpTree = sender as TreeList;
                DevExpress.Utils.Drawing.IndicatorObjectInfoArgs args = e.ObjectArgs as DevExpress.Utils.Drawing.IndicatorObjectInfoArgs;
                if (args != null)
                {
                    int rowNum = tmpTree.GetVisibleIndexByNode(e.Node) + 1;
                    args.DisplayText = rowNum.ToString();
                }
            };
            treeList.IndicatorWidth = (treeList.Nodes.Count + 1).ToString().Length * 9 + 23; //行指示器宽度(treeList.OptionsView.ShowIndicator = true时有效)
            treeList.RowHeight      = 22;                                                    //行高
            treeList.OptionsCustomization.AllowColumnMoving = false;                         //不允许拖动列
            foreach (TreeListColumn treeListColumn in treeList.Columns)
            {
                treeListColumn.OptionsColumn.AllowFocus = false; //不允许列头有焦点
                treeListColumn.OptionsColumn.AllowMove  = false; //列头不允许拖动
                treeListColumn.OptionsColumn.AllowSort  = false; //不允许排序
                treeListColumn.OptionsColumn.AllowSize  = false; //不允许拖动改变列宽
                treeListColumn.OptionsColumn.FixedWidth = false; //固定宽度,仅在treeList.OptionsView.AutoWidth = true时有效
            }
            if (GetEmptyDisplayInfo != null)
            {
                //无数据时,显示文本
                treeList.CustomDrawEmptyArea += (sender, e) =>
                {
                    if (treeList.VisibleNodesCount <= 0)
                    {
                        string    strHint   = GetEmptyDisplayInfo();
                        Font      font      = new Font(PubFontFamily, 30, FontStyle.Regular);
                        Graphics  g         = treeList.CreateGraphics();
                        SizeF     sizeF     = g.MeasureString(strHint, font);
                        Rectangle rectangle = new Rectangle(
                            (int)((e.Bounds.Width - sizeF.Width) / 2), (int)((e.Bounds.Height - sizeF.Height) / 2) + 20,
                            e.Bounds.Width - 5, e.Bounds.Height - 5);
                        e.Graphics.FillRegion(Brushes.White, e.EmptyAreaRegion);
                        e.Graphics.DrawString(strHint, font, Brushes.Black, rectangle);
                        g.Dispose();
                        e.Handled = true;
                    }
                };
            }
        }