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

Event MouseLeftButtonDown on GridViewHeaderCell

1 Answer 241 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sebastien
Top achievements
Rank 1
Sebastien asked on 31 Jul 2015, 06:35 PM

Hi,

 I tried to implement the MouseLeftButtonDown event and the CellDoubleClick event on a style:

<Style TargetType="{x:Type telerik:GridViewHeaderCell}">
            <Setter Property="Foreground" Value="White"/>
            <EventSetter Event="CellDoubleClick" Handler="SelectDeselectColumn"/>
            <EventSetter Event="MouseLeftButtonDown " Handler="SelectDeselectColumn2"/>
</Style>

 

The "CellDoubleClick" event works fine but the "MouseLeftButtonDown" event doesn't work! I tried each event alone in the style and the MouseLeftButtonDown never works!

In the class "GridViewHeaderCell" there is no event accessible for MouseLeftButtonDown, there is only a method called "OnMouseLeftButtonDown" My guess is that the event MouseLeftButtonDown (or MouseDown) is already handled somewhere else...

If I want to use the method "OnMouseLeftButtonDown" I have to create a new ​child class that the parent is "GridViewHeaderCell". But I don't know where to allocate the new class in the code. Is there a event like "AutogeneratingCoumn"?

Is there any other options possible to support the MouseLeftButtonDown event or a single click?

 

 

 ​

 

 

 

1 Answer, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 03 Aug 2015, 08:53 AM
Hi,

The reason for this is that the event is internally handled by RadGridView.
You can try subscribing for the click event of the GridViewHeaderCell (with HandledEventsToo) and get the information you need from the clicked HeaderCell.
For example:
this.AddHandler(FrameworkElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(OnMouseLeftButtonDown), true);
 
private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    var result = (e.OriginalSource as FrameworkElement).ParentOfType<GridViewHeaderCell>();
    if (result != null)
    {
        // the user have clicked on a header cell
         var column = result.Column;
    }
}

I hope this helps. 

Regards,
Dimitrina
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
GridView
Asked by
Sebastien
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Share this question
or