Handle the Double Click

8 posts, 1 answers
  1. Vuyiswa
    Vuyiswa avatar
    188 posts
    Member since:
    Jan 2010

    Posted 06 May 2011 Link to this post

    Good Day

    Is there a way to handle a Double click on a Datagrid row ?

    Thanks
  2. Vuyiswa
    Vuyiswa avatar
    188 posts
    Member since:
    Jan 2010

    Posted 06 May 2011 Link to this post

    Sorry Guys for posting without checking the grid events. i found the exact event for Double Click.

    Thanks
  3. Answer
    Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 06 May 2011 Link to this post

    Hello Vuyiswa Maseko,

    Are you looking for the Control's main DoubleClick or for the CellDoubleClick?
    I would suggest using the CellDoubleClick event if you want to receive events just from cells.

    Hope this helps, if you have any other questions or comments, please let me know,

    Best Regards,
    Emanuel Varga

    Telerik WinForms MVP
  4. Idris
    Idris avatar
    1 posts
    Member since:
    May 2013

    Posted 13 Nov 2013 Link to this post

    Hi Emanuel
    on CellDoubleClick how to understand it clicked left mouse button or right mouse button?
    it fires both of them.
    thank you
  5. Dimitar
    Admin
    Dimitar avatar
    1929 posts

    Posted 15 Nov 2013 Link to this post

    Hello Idris,

    Thank you for writing.

    There is no way to detect which mouse button is clicked in CellDoubleClick. Nevertheless you can use the MouseDoubleClick and get the corresponding cell there:
    void radGridView1_MouseDoubleClick(object sender, MouseEventArgs e)
    {
        if (e.Button == System.Windows.Forms.MouseButtons.Left)
        {
            GridCellElement cell = radGridView1.ElementTree.GetElementAtPoint(e.Location) as GridCellElement;
            if (cell != null)
            {
                Console.WriteLine(cell.Value);
            }
        }           
    }

    I hope this will be useful. Should you have further questions, I would be glad to help.

    Regards,
    Dimitar
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  6. Brajendra
    Brajendra avatar
    8 posts
    Member since:
    Aug 2017

    Posted 26 Oct in reply to Dimitar Link to this post

    Hi Dimitar,

    Thanks for this solution, but its somewhat limiting if radgridview has sorting enabled, following is my issue:

     

    I was looking for this issue, though solution for which mouse got clicked is getting resolved but I'm facing a strange issue that I would like to mention.

    If the grid is double-clicked I was using following method:

    private void gridDQ_CellDoubleClick(object sender, GridViewCellEventArgs e)
            {
                GridCellElement cell = (GridCellElement)sender;
                
                if (cell.RowIndex != -1 && cell.ColumnIndex != -1)
                {

      //Commented following code as I was getting first two rows data correct and for other rows I was getting value of two rows below

                     //int intCurrOrderNo = int.Parse(gridDQ.Rows[cell.RowIndex].Cells[2].Value.ToString());    

                    int intCurrOrderNo = int.Parse(gridDQ.Rows[e.RowIndex].Cells[2].Value.ToString());

                    if (intCurrOrderNo > 0)
                    {
                        //Some work here...
                    }
                }
            }

    After having look at ur code I re-wrote the desired code as:

     private void gridDQ_MouseDoubleClick(object sender, MouseEventArgs e)
            {
                if (e.Button == System.Windows.Forms.MouseButtons.Left)
                {
                    GridCellElement cell = gridDQ.ElementTree.GetElementAtPoint(e.Location) as GridCellElement;

                    if (cell != null)
                    {
                        int intCurrOrderNo = int.Parse(gridDisbursementQueue.Rows[cell.RowIndex].Cells[2].Value.ToString());

                        int intTemp = 0;
                    }
                }

           }

    My mouse-button identification issue was sorted out but I'm getting the wrong value from "OrderNo" field afer grid is sorted on click of header column.

     

    Thanks & Regards

    Braj

  7. Brajendra
    Brajendra avatar
    8 posts
    Member since:
    Aug 2017

    Posted 26 Oct in reply to Brajendra Link to this post

    Hi Dimitar,

    CODE CORRECTION (In my previous post I've used gridDisbursementQueue instead of gridDQ, plz consider it as gridDQ)

    Thanks for this solution, but its somewhat limiting if radgridview has sorting enabled, following is my issue:

    I was looking for this issue, though solution for which mouse got clicked is getting resolved but I'm facing a strange issue that I would like to mention.
    If the grid is double-clicked I was using following method:
    private void gridDQ_CellDoubleClick(object sender, GridViewCellEventArgs e)
            {
                GridCellElement cell = (GridCellElement)sender;
                
                if (cell.RowIndex != -1 && cell.ColumnIndex != -1)
                {
      //Commented following code as I was getting first two rows data correct and for other rows I was getting value of two rows below
                     //int intCurrOrderNo = int.Parse(gridDQ.Rows[cell.RowIndex].Cells[2].Value.ToString());    

     

        //Getting proper cell value when using e.RowIndex instead of cell.RowIndex by following code:

        int intCurrOrderNo = int.Parse(gridDQ.Rows[e.RowIndex].Cells[2].Value.ToString());

                    if (intCurrOrderNo > 0)
                    {
                        //Some work here...
                    }
                }
            }
    After having look at ur code I re-wrote the desired code as:
     private void gridDQ_MouseDoubleClick(object sender, MouseEventArgs e)
            {
                if (e.Button == System.Windows.Forms.MouseButtons.Left)
                {
                    GridCellElement cell = gridDQ.ElementTree.GetElementAtPoint(e.Location) as GridCellElement;

                    if (cell != null)
                    {
                        int intCurrOrderNo = int.Parse(gridDQ.Rows[cell.RowIndex].Cells[2].Value.ToString());

                        int intTemp = 0;
                    }
                }
           }
    My mouse-button identification issue was sorted out but I'm getting the wrong value from "OrderNo" field afer grid is sorted on click of header column.

    Thanks & Regards
    Braj

  8. Dimitar
    Admin
    Dimitar avatar
    1929 posts

    Posted 30 Oct Link to this post

    Hello Brajendra,

    In the first case, the row is available in the event arguments. For example, you can get the value like this:
    int intCurrOrderNo = int.Parse(e.Row.Cells[2].Value.ToString());

    In the second case, you can get the row from the cell instance:
    cell.RowInfo.Cells[2].Value.ToString()

    When operations like sorting and filtering are performed the grid does not change the indexes in the original collection, however, the cell elements indexes are different and they depend on the currently visible cells. Detailed information is available here: Rows vs ChildRows.

    I hope this will be useful. 

    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top