【问题标题】:Set border for entire row when selected in TreeList DevExpress在 TreeList DevExpress 中选择时为整行设置边框
【发布时间】:2014-10-02 11:47:36
【问题描述】:

我有以下问题。我希望 TreeList 中选定 NodeCell 周围的虚线边框包裹整行而不是我单击的单元格。行的选择很好(即,无论聚焦哪个单元格,都会选择整行),但是我希望在单击边框时,边框会突出显示整行,而不仅仅是该行中的特定单元格。我已经设置好了:

treeList.OptionsSelection.EnableAppearanceFocusedCell = false;

但似乎我需要一个类似于 GridView 的 TreeList 属性,例如:

gridView1.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus;

我附上截图举例说明:

所选行以蓝色突出显示(正确),但边框突出显示特定单元格,尽管整个行实际上已被选中。我希望边框包裹整行,而不仅仅是一个单元格。

【问题讨论】:

    标签: c# winforms gridview devexpress


    【解决方案1】:

    DevExpress support forum 开始 - 目前 XtraTree 中没有 FocusRectStyle 的等价物。

    但是,如果您需要虚线边框 - 您可以自己绘制。

    首先,设置treeList.OptionsSelection.EnableAppearanceFocusedCell = false;

    接下来,用你想在班级某处绘制边框的钢笔定义:

    private readonly Pen _PenBorder = new Pen(Color.Black) {DashStyle = DashStyle.Dot};
    

    最后,通过以下方式处理 treeList.CustomDrawNodeCell 事件:

    void TreeListCustomDrawNodeCell(object sender, CustomDrawNodeCellEventArgs e)
    {
        if (e.Node.Focused)
        {
            e.Graphics.DrawLine(_PenBorder, e.Bounds.Left, e.Bounds.Top, e.Bounds.Right, e.Bounds.Top);
            e.Graphics.DrawLine(_PenBorder, e.Bounds.Left, e.Bounds.Bottom - 1, e.Bounds.Right, e.Bounds.Bottom - 1);
    
            if (e.Column.VisibleIndex == 0)
                e.Graphics.DrawLine(_PenBorder, e.Bounds.Left, e.Bounds.Top, e.Bounds.Left, e.Bounds.Bottom);
    
            if (e.Column.VisibleIndex == treeList.VisibleColumns.Count - 1)
                e.Graphics.DrawLine(_PenBorder, e.Bounds.Right - 1, e.Bounds.Top, e.Bounds.Right - 1, e.Bounds.Bottom);
        }
    }
    

    【讨论】:

    • 是的,我认为这将是一个解决方案,但我希望有一些“更便宜”的东西。不管怎样,谢谢你的建议,我试试看效果如何
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-10
    • 1970-01-01
    相关资源
    最近更新 更多