This is a migrated thread and some comments may be shown as answers.

Edit cell on single clicl only, and not double click ?

1 Answer 279 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 23 Jul 2014, 06:28 AM
Hi.

I was wondering if it's possible with a RadGridView to have the double click event not enable edits on the cell ?
Single click edits work fine, but double clicks activate another view, and I do not want the cell being in an editable state at this point.

Is there a solution to this ?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Boris
Telerik team
answered on 25 Jul 2014, 12:03 PM
Hello Michael,

A possible approach is to use the BeginningEdit event to cancel the edit of the cell, when the double click occurs. In order to do that you can do the following:

1)  set two Boolean flags(isEditMouseInitiated and isDoubleClick). Where isEditMouseInitiated and isDoubleClick are used to indicate, respectively that an edit operation was initiated by a mouse activity and you have a double click.
2)  add a handlers for the MouseDoubleClickEvent and MouseLeftButtonUpEvent events, to set the Boolean flags to the appropriate values - isDoubleClick is set to false, when the MouseDoubleClickEvent event triggers and the isEditMouseInitiated is set to true, when the MouseLeftButtonUpEvent triggers.

bool isDoubleClick = true;
bool isEditMouseInitiated = true;
 
DispatcherTimer dispatcherTimer = new DispatcherTimer();
public MainWindow()
{
    InitializeComponent();
 
    this.AddHandler(Control.MouseDoubleClickEvent, new MouseButtonEventHandler((s, e) =>
    {
        isDoubleClick = false;
    }), true);
    this.AddHandler(Control.MouseLeftButtonUpEvent, new MouseButtonEventHandler((s, e) =>
    {
        isEditMouseInitiated = true;
    }), true);
}

3)  use a DispatcherTimer in the BeginingEdit event handler to set an interval of time and attach an event handler to it's Tick event to detect if a second click has occurred. If the isDoubleClick flag or the IsEnabled property of the DispatcherTimer are set to false the GridView will not enter edit mode.


 
        private void clubsGrid_BeginningEdit(object sender, GridViewBeginningEditRoutedEventArgs e)
        {
            if (isEditMouseInitiated)
            {
                e.Cancel = true;
                dispatcherTimer.Tick += dispatcherTimer_Tick;
                dispatcherTimer.Interval = new TimeSpan(2500000);
                dispatcherTimer.Start();
            }
        }
 
        void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            if (dispatcherTimer.IsEnabled && isDoubleClick)
            {
                clubsGrid.BeginEdit();
                isEditMouseInitiated = false;
            }
            else
            {
                isDoubleClick = true;
            }
 
            dispatcherTimer.Stop();
        }

Also, I attached a sample project that demonstrates the suggested approach.

I hope this helps.

Regards,
Boris Penev
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
Michael
Top achievements
Rank 1
Answers by
Boris
Telerik team
Share this question
or