【问题标题】:DevExpress DXGrid column header double click eventDevExpress DXGrid 列标题双击事件
【发布时间】:2012-02-28 16:29:29
【问题描述】:

当用户双击列标题时,我必须选中/取消选中列中的所有复选框(切换)。

如何在DevExpress DxGrid 控件中实现此行为?

我搜索了 DevExpress 支持论坛,但没有找到解决方案。

另外,我正在研究 MVVM 模式。

【问题讨论】:

    标签: c# wpf devexpress


    【解决方案1】:

    此案例适用于 WinForms,尚未在 WPF 中测试,我发布了它可能会引导您了解一些亮点:

    有一个解决方法来完成这个行为,你必须实现yourGrid_DoubleClick事件处理程序,然后计算鼠标点击的hit Info,点击信息对象会告诉你双击是否在一个列上,一些喜欢:

     private void yourGridViewName_DoubleClick(object sender, EventArgs e)
            {
                DevExpress.XtraGrid.Views.Grid.GridView sndr =
                        sender as DevExpress.XtraGrid.Views.Grid.GridView;
    
                DevExpress.Utils.DXMouseEventArgs dxMouseEventArgs =
                    e as DevExpress.Utils.DXMouseEventArgs;
    
    
                DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo hitInfo =
                   sndr.CalcHitInfo(dxMouseEventArgs.Location);
    
                if (hitInfo.InColumn)
                {
                   string x = hitInfo.Column.Name;
    
                  //Rest of your logic goes here after getting the column name, 
                 //You might now loop over your grid's data and do your logic
               }
        }
    

    但您必须注意,此操作不会阻止该列标题的排序,您可能需要禁用此网格的排序

    希望这会有所帮助。

    【讨论】:

    • 感谢您的回复。我已经在使用鼠标双击事件。当我双击一行时,我正在成功检查/取消选中所选行的所有 cb,但是对于列 cb 检查/取消选中,我必须实现列标题双击事件,但不知道如何。 ..
    • 使用相同的事件grdiDoubleClick 并检查hitInfo.InColumn 属性以指示用户double-clicked 列标题还是网格的其他部分,这应该适合您。
    猜你喜欢
    • 1970-01-01
    • 2011-12-05
    • 2014-10-29
    • 1970-01-01
    • 1970-01-01
    • 2019-02-09
    • 2012-01-14
    • 2023-04-04
    • 1970-01-01
    相关资源
    最近更新 更多