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

Double Click Open Window

1 Answer 343 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 05 Aug 2008, 01:53 PM
How can I open a second window for editing when a row in the grid is double clicked?

I have been trying to use the MouseDoubleClick event on the grid and that almost works as desired. When the event is fired I use the CurrentRecord value to determine which record needs to be shown in the new window. The problem is when someone double clicks on a part of the grid that is not a row. For example, double clicking on the header will still open the CurrentRecord even thought that record was not clicked on. I have MultipleSelect set to false so only one record can be selected at a time.

1 Answer, 1 is accepted

Sort by
0
Accepted
Jimmy
Telerik team
answered on 06 Aug 2008, 02:27 PM
Hello Tim,

Our GridViewRow has a RoutedEvent called PreviewEditStart that is fired right before the row enters in edit mode (that is after a mouse double-click is registered on any of its cells). You can subscribe to the event and get to the GridViewRow like so:

    ... 
    this.Grid.AddHandler(GridViewRow.PreviewEditStart, new EventHandler<RecordCancelRoutedEventArgs>(GridRowPreviewEditStart)); 
    ... 
 
    private void GridRowPreviewEditStart(object sender, RecordCancelRoutedEventArgs e) 
    { 
        GridViewRow row = (GridViewRow) e.OriginalSource; 
    } 
 

However keep in mind that this method will only work if you double-click on a non read-only GridViewColumn.

A more general solution would be to go with your approach and subscribe to the system double-click event. To avoid your problem of executing code every time a double-click occurs but rather only handling those double-clicks registered from within a GridViewRow, a VisualTreeHelper will be used iteratively in the event handler to find occurrences of GridViewRow. If an instance of RadGridView is found first we will return knowing that we have not double-clicked anywhere inside a GridViewRow.

The event handler for Mouse.DoubleClick may look something like this:

  
  private void Grid_MouseDoubleClick(object sender, MouseButtonEventArgs e) 
        { 
            DependencyObject uiElement = (DependencyObject)e.OriginalSource; 
            while (!(uiElement is GridViewRow)) 
            { 
                uiElement = VisualTreeHelper.GetParent(uiElement); 
                if (uiElement is RadGridView) 
                    return
            } 
 
            GridViewRow row = (GridViewRow) uiElement; 
            ... do something here 
        } 


Hope this works for you!








Kind regards,
Jimmy
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
Tim
Top achievements
Rank 1
Answers by
Jimmy
Telerik team
Share this question
or