Telerik WinForms: Double clicking not distinguishing with single clicking

泄露秘密 提交于 2019-12-25 16:52:02

问题


We have inherited a project that uses RADGrid. It has both events for double and single clicking enabled.

But when DoubleClick is fired, so are Click and CellBeginEdit,...

I want to cancel Click, CellBeginEdit or others when DoubleClick is fired.


回答1:


I have an Inherited class Sheet from Telerik.WinControls.UI.RadGridView that I use as grid control in my project.

This resume what is needed to solve the problem:

public partial class Sheet : Telerik.WinControls.UI.RadGridView
{

    //System Time to wait between Click and DoubleClick
    private int _doubleClickTime = 500;
    private bool _doubleClickRaised = false;
    private bool _doubleClickCancelEdit = false;

    public void FpSpread()
    {
        _doubleClickTime = System.Windows.Forms.SystemInformation.DoubleClickTime;
        //...
    }


    protected override void OnMouseDoubleClick(MouseEventArgs e)
    {
        _doubleClickRaised = true;
        _doubleClickCancelEdit = true;

        base.OnMouseDoubleClick(e);
    }

    protected override void OnMouseClick(MouseEventArgs e)
    {
        //Doing what Telerik doesn't

        //Wait system time needed for DoubleClick
        System.Threading.Thread.Sleep(_doubleClickTime + 10);
        Application.DoEvents();
        if (_doubleClickRaised)
        {
            _doubleClickRaised = false;
            return;
        }

        base.OnMouseClick(e);
    }

    //This only when editable cells...
    protected override void OnCellBeginEdit(object sender, GridViewCellCancelEventArgs e)
    {
        if (_doubleClickCancelEdit)
        {
            _doubleClickCancelEdit = false;
            e.Cancel = true;
        }
        base.OnCellBeginEdit(sender, e);
    }

}

I hope this helps!!



来源:https://stackoverflow.com/questions/43652295/telerik-winforms-double-clicking-not-distinguishing-with-single-clicking

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!