7 Answers, 1 is accepted
Thanks
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
on CellDoubleClick how to understand it clicked left mouse button or right mouse button?
it fires both of them.
thank you
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
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 >>
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
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
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