MouseDoubleClick isn't working in beta 3 release 15-10

6 posts, 0 answers
  1. Duc Hoang Viet
    Duc Hoang Viet avatar
    2 posts
    Member since:
    Oct 2009

    Posted 17 Oct 2009 Link to this post

    In beta 2, I used to addHandler for GridViewCell's MouseDoubleClickEvent to handler event double click on one row. But in beta 3, this seem not working. Is there any way to fix this?
  2. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 21 Oct 2009 Link to this post

    Hi Duc Hoang Viet,

    Thank you for reporting this issue. We will fix it for the official Q3 release. For the time being you can use the following workaround: This a class that we use in RadGridView to implement double clicks:\

    public class DoubleClick
    {
        private UIElement element;
        private DispatcherTimer doubleClickTimer;
        private int clickCount;
      
        internal event EventHandler DoubleClickEvent;
      
        public DoubleClick(UIElement element)
        {
            this.element = element;
            this.element.AddHandler(UIElement.MouseLeftButtonDownEvent, 
                new MouseButtonEventHandler(element_MouseLeftButtonDown), true);
        }
      
        void element_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.StartDoubleClickTime();
            if (this.clickCount > 0)
                this.OnDoubleClick();
      
            this.clickCount++;
        }
      
        private void StartDoubleClickTime()
        {
            if (this.doubleClickTimer != null)
            {
                this.doubleClickTimer.Stop();
            }
      
            this.doubleClickTimer = new DispatcherTimer();
            this.doubleClickTimer.Interval = TimeSpan.FromMilliseconds(300);
            this.doubleClickTimer.Tick += new EventHandler(doubleClickTimer_Tick);
            this.doubleClickTimer.Start();
        }
      
        void doubleClickTimer_Tick(object sender, EventArgs e)
        {
            this.doubleClickTimer.Stop();
            this.clickCount = 0;
        }
      
        private void OnDoubleClick()
        {
            if (this.DoubleClickEvent != null)
                this.DoubleClickEvent(this.element, new EventArgs());
        }
    }

    Once you have this class in your project you just have to utilize it to be able to handle MouseDoubleCLick events:

    public MainPage()
    {
        InitializeComponent();
      
        this.playersGrid.ItemsSource = Club.GetPlayers();
        this.playersGrid.RowLoaded += new System.EventHandler<Telerik.Windows.Controls.GridView.RowLoadedEventArgs>(playersGrid_RowLoaded);
    }
      
    void playersGrid_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
    {
        if (e.Row is GridViewHeaderRow || e.Row is GridViewNewRow || e.Row is GridViewFooterRow)
            return;
      
        var row = e.Row as GridViewRow;
      
      
        foreach (var item in row.Cells)
        {
            DoubleClick click = new DoubleClick(item);
            click.DoubleClickEvent += new System.EventHandler(click_DoubleClickEvent);
        }
          
    }
      
    void click_DoubleClickEvent(object sender, System.EventArgs e)
    {
          
    }

    Hope this is helpful.


    Best wishes,
    Milan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. david ocasio
    david ocasio avatar
    22 posts
    Member since:
    Apr 2006

    Posted 22 Oct 2009 Link to this post

    I beleive the "internal" has to be removed from

    internal event EventHandler DoubleClickEvent

     At least in my code it had to
    since i put class "DoubleClick" in a class library.

    thanks
    dco
  4. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 23 Oct 2009 Link to this post

    Hello david ocasio,

    Yes, you are absolutely correct. I forgot to remove it.

    Best wishes,
    Milan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Damian Andrade
    Damian Andrade avatar
    2 posts
    Member since:
    Sep 2009

    Posted 26 Oct 2009 Link to this post

    I have same problem, but in this screen not exits cells in my row, after run event RowLoaded is present the row in the grid and not atach to event double click but not cells
  6. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 27 Oct 2009 Link to this post

    Hi Damian Andrade,

    This is a known issue in Beta 2. You could workaround that limitation by subscribing to the DoubleClickEvent of RadGridView and in the DoubleClickEvent handler check if the clicked element is cell. Here is a sample solution with a minor modification to the DoubleClick class:

    public MainPage()
    {
        InitializeComponent();
      
        this.playersGrid.ItemsSource = Club.GetPlayers();
        DoubleClick click = new DoubleClick(this.playersGrid);
        click.DoubleClickEvent += new System.Windows.Input.MouseButtonEventHandler(click_DoubleClickEvent);
    }
      
    void click_DoubleClickEvent(object sender, System.Windows.Input.MouseButtonEventArgs e)
    {
        FrameworkElement clickedElement = sender as FrameworkElement;
      
        if (clickedElement is GridViewCell)
        {
            // cell was clicked
        }
        else
        {
            var cell = clickedElement.ParentOfType<GridViewCell>();
      
            if (cell != null)
            {
                // cell was clicked
            }
        }
    }

    public class DoubleClick
    {
        private UIElement element;
        private DispatcherTimer doubleClickTimer;
        private int clickCount;
      
        internal event MouseButtonEventHandler DoubleClickEvent;
      
        public DoubleClick(UIElement element)
        {
            this.element = element;
            this.element.AddHandler(UIElement.MouseLeftButtonDownEvent,
                new MouseButtonEventHandler(element_MouseLeftButtonDown), true);
        }
      
        void element_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.StartDoubleClickTime();
            if (this.clickCount > 0)
                this.OnDoubleClick(e);
      
            this.clickCount++;
        }
      
        private void StartDoubleClickTime()
        {
            if (this.doubleClickTimer != null)
            {
                this.doubleClickTimer.Stop();
            }
      
            this.doubleClickTimer = new DispatcherTimer();
            this.doubleClickTimer.Interval = TimeSpan.FromMilliseconds(300);
            this.doubleClickTimer.Tick += new EventHandler(doubleClickTimer_Tick);
            this.doubleClickTimer.Start();
        }
      
        void doubleClickTimer_Tick(object sender, EventArgs e)
        {
            this.doubleClickTimer.Stop();
            this.clickCount = 0;
        }
      
        private void OnDoubleClick(MouseButtonEventArgs args)
        {
            if (this.DoubleClickEvent != null)
                this.DoubleClickEvent(this.element, args);
        }
    }

    Sincerely yours,
    Milan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top