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

Doubleclick row in grid - ignore scrollbar?

7 Answers 188 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Patrick Barranis
Top achievements
Rank 1
Patrick Barranis asked on 12 Jul 2010, 03:38 PM
Hi.  I'm trying to do something straightforward but getting caught on an odd problem.  I want to pop open a dialog when a user double-clicks on a row in a grid.  Not seeing an event specifically for "double-clicking on a row", I am hooking RadGridview.DoubleClick.  When the event handler is called, I check to see if just one row is selected, and if so, I pop open my dialog.

However, I am having a problem where if the user selects a row (single-click), then double-clicks the scrollbar I cannot distinguish that the user didn't double-click on a row.  How can I prevent this from happening?

I think I need one of the following:
* A better event to hook
* A way to programmatically figure out if the user double-clicked on a row
* A way to programmatically figure out if the double-click is on the scrollbar so that I might ignore it (NOTE: the doubleclick event does not provide the mouse coordinates, so this is hard)

I'm running VS 2008, .NET 3.5, and Telerik WinForms controls 2010 Q1 SP2 all on Win 7 x64.

Thanks,
Patrick

7 Answers, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 15 Jul 2010, 03:42 PM
Hi Patrick Barranis,

Thank you for writing.

You are on the right track with hooking the grid's DoubleClick event. You only have to check if the GridDataCell element is under the mouse cursor when performing the double click operation. That can be done in MouseDown event. Please consider the following code:
private bool _dataCellClicked = false;
  
private void radGridView1_MouseDown(object sender, MouseEventArgs e)
{
    _dataCellClicked = false;
    GridDataCellElement cell = this.radGridView1.ElementTree.GetElementAtPoint(e.Location) as GridDataCellElement;
    if (cell != null) {
        _dataCellClicked = true;
    }
}
  
private void radGridView1_DoubleClick(object sender, EventArgs e)
{
    if (_dataCellClicked) {
        //do something 
    }
}

I hope this helps. Let me know if you have any additional questions.

Sincerely yours,
Martin Vasilev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Patrick Barranis
Top achievements
Rank 1
answered on 15 Jul 2010, 04:17 PM
Wow.  That's a lot of extra lines just to get a simple DoubleClick to work exactly as it does on the System.Windows.Forms.DataGridView.  I know Telerik is all about giving more under-the-hood power to the developer, but it's obviously a tradeoff, isn't it?  Sort of takes the "RAD" out of the controls...

Thanks for your help!  I'll stick this in my code and run with it!

Patrick
0
Martin Vasilev
Telerik team
answered on 20 Jul 2010, 05:49 PM
Hi Patrick Barranis,

A have to admit that this requires more code than doing the same thing in DataGridView, however as you have pointed that is the trade off to allow a very wide feature richness in our controls. We also provide  outstanding support services to help in resolving particular cases which are outbound of the provided documentation. So, do not hesitate to use our support system for any questions, which you have regarding our products.

 
Regards,
Martin Vasilev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 21 Jul 2010, 06:13 AM
Hello,

I would suggest an alternative to the previous solution, and one pretty easy to use and understand. The first thing is that you should use the CellDoubleClick event for what you are trying to do.
In the second phase you have to options, either ignore if the user double clicks on something different:
if (e.Row.Cells.Count == 0 || e.RowIndex == -1)
{
     return;
}

Or if you want a more (user mistake proof) grid you can adapt the previous example to check if the currentRow is not null and then take that row.

With this event the event won't fire if you click on the scrollbars, but that check is there if the user double clicks the header or an empty line.

Please let me know how it went,
Emanuel Varga
0
Patrick Barranis
Top achievements
Rank 1
answered on 21 Jul 2010, 05:12 PM
I had missed the CellDoubleClick event; thanks very much Emanuel!  What are the differences between that event and the normal DoubleClick?  What I'm really asking is... Are there any side-effects of using that event that I should be aware of?

Thanks!
0
Emanuel Varga
Top achievements
Rank 1
answered on 21 Jul 2010, 07:14 PM
Hello Patrick,

The double click event is for the entire control, that is usually implemented when you want something to always happen when you double click anywhere in the control area, not a row or a cell and it has nothing to do with selection.

The previous solution with checking the area where the cursor is on double click seems like overkill to me.

There should be no drawbacks with this (at least as far as i am aware) considering this is the normal grid behavior (part of microsoft's best practices if I'm not mistaken).

Hope this help,
0
Martin Vasilev
Telerik team
answered on 26 Jul 2010, 04:49 PM
Hi guys,

As Emanuel said, there are no drawbacks of using CellDoubleClick event in comparison with DoubleClick. Actually, CellDoubleClick event determines the cell click in a very similar way as shown in my first answer. It is possible that the CellDoubleClick usage could be more convenient for particular scenarios and the only difference is that DoubleClick is more flexible depending of the goals.

A bit off topic, I would like to thank Emanuel for the good explanations in his replies.

Let me know if there are any additional questions.

Greetings,
Martin Vasilev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Patrick Barranis
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Patrick Barranis
Top achievements
Rank 1
Emanuel Varga
Top achievements
Rank 1
Share this question
or