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

Handle the Double Click

7 Answers 450 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Vuyiswa
Top achievements
Rank 2
Vuyiswa asked on 06 May 2011, 07:01 AM
Good Day

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

Thanks

7 Answers, 1 is accepted

Sort by
0
Vuyiswa
Top achievements
Rank 2
answered on 06 May 2011, 07:15 AM
Sorry Guys for posting without checking the grid events. i found the exact event for Double Click.

Thanks
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 06 May 2011, 07:54 AM
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
0
Idris
Top achievements
Rank 1
answered on 13 Nov 2013, 11:06 AM
Hi Emanuel
on CellDoubleClick how to understand it clicked left mouse button or right mouse button?
it fires both of them.
thank you
0
Dimitar
Telerik team
answered on 15 Nov 2013, 01:48 PM
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 >>
0
Brajendra
Top achievements
Rank 1
answered on 26 Oct 2017, 12:54 PM

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

0
Brajendra
Top achievements
Rank 1
answered on 26 Oct 2017, 01:03 PM

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

0
Dimitar
Telerik team
answered on 30 Oct 2017, 10:53 AM
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.
Tags
GridView
Asked by
Vuyiswa
Top achievements
Rank 2
Answers by
Vuyiswa
Top achievements
Rank 2
Emanuel Varga
Top achievements
Rank 1
Idris
Top achievements
Rank 1
Dimitar
Telerik team
Brajendra
Top achievements
Rank 1
Share this question
or