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

Detect mouse click position in header cell

4 Answers 430 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Vincent
Top achievements
Rank 1
Vincent asked on 07 Aug 2012, 02:52 PM
Hi !
I'm actually wondering if it is possible to detect WHERE a mouse click occurs in a cell (mainly a header cell).
The CellClick event args doesn't return the mouse position in the cell, only the row / column, making my test impossible
At the opposite, inside MouseClick event capture, the GetChildAtPoiint() function returns always null.

My goal is the following : I want to use a particular area (top right corner of a header cell) to perform a particular task (I'm rendering the area with the CellPaint event)

4 Answers, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 10 Aug 2012, 11:42 AM
Hello Vincent,

Thank you for writing.

The cleanest solution for this case would be to create a custom header element and add an element which would show a plus/minus image to it. Please find attached an example project which demonstrates how to create this custom header cell and how to use it in the grid.

I hope this will help. Should you have further questions, I would be glad to help.
 
All the best,
Ivan Petrov
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Vincent
Top achievements
Rank 1
answered on 17 Aug 2012, 08:48 AM
Nice example.
This really helps me ;-)
However, I want to PAINT plus / minus sign, not to display an image.
So I suppose I need to override the PaintContent() function of the LightVisualElement class, am I right ?
0
Vincent
Top achievements
Rank 1
answered on 17 Aug 2012, 10:27 AM
Back again with some weird issues.

1- It seems I got somme "click-thru" behavior but it's not systematic.
I used the CellClick event on headers (at the grid view level) to activate particular functions in my program and, sometimes, if I click on the child control (the + sign), it doesn't go into its MouseUp event but fires the CellClick at the RadGridView level instead.
2- When I scroll the table horizontally, the child controls (the + signs) disappear or appear in the wrong column.

I also discovered that my OnClick event on the grid is executed BEFORE the MouseUp event of my LightVisualElement, which seems totally illogical.
Also, why don't you provide click identification in the OnClick event ? This event occurs no matter the kind of click (left, right, middle) and I didn"t find the way to know it ...
0
Ivan Petrov
Telerik team
answered on 22 Aug 2012, 10:11 AM
Hi Vincent,

Thank you for writing back.

I tried to reproduce your first issue but I was not able to do so. I would kindly ask you to try and find a sequence of actions which will reproduce the issue every time so I can investigate it further.
Your second issue is caused by the grid UI virtualization. To solve it you can create a custom column which will holds your custom cell as well as the current state of the cell. I have attached a modified version of the example where the above changes are implemented.
The sequence in which events are fired is MouseDown, Click, MouseClick, MouseUp. You can test this with a standard button control. The reason the CellClick event does not provide information on the mouse button that triggered it is because the event is fired from the grid Click event and the event arguments of the Click event do not provide such information.

I hope this will be informative. Should you have further questions, I would be glad to assist.
 
Regards,
Ivan Petrov
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
Vincent
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Vincent
Top achievements
Rank 1
Share this question
or