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

[Solved] Unable to catch mouse events in a child table

4 Answers 159 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jakub
Top achievements
Rank 1
Jakub asked on 06 Oct 2009, 01:57 PM
Hello,

I just ran into a big problem with the GridView control. I have used the gridview control before and I was able to implement the double-click functionality without any problems. However, now my scenario is somewhat more complex and some rows of my gridview contain child tables. Here is how the gridview is defined in my XAML:

    <telerik:RadGridView x:Name="MyGrid"
                         AutoGenerateColumns="False" 
                         MultipleSelect="True" 
                         Background="White" 
                         ShowGroupPanel="False" 
                         CanUserReorderColumns="False" 
                         IsFilteringAllowed="False" 
                         IsReadOnly="True" 
                         ColumnsWidthMode="Fill"
      <telerik:RadGridView.Columns> 
        <telerik:GridViewDataColumn Header="Name" 
                                    DataMemberBinding="{Binding Name}" /> 
        <telerik:GridViewDataColumn Header="Created" 
                                    DataMemberBinding="{Binding Created}" 
                                    Width="200" /> 
      </telerik:RadGridView.Columns> 
      <telerik:RadGridView.HierarchyChildTemplate> 
        <DataTemplate> 
          <telerikGridView:GridViewDataControl AutoGenerateColumns="False" 
                                         MultipleSelect="True" 
                                         Background="White" 
                                         ShowGroupPanel="False" 
                                         CanUserReorderColumns="False" 
                                         IsFilteringAllowed="False" 
                                         IsReadOnly="True" 
                                         ColumnsWidthMode="Fill"
            <telerikGridView:GridViewDataControl.Columns> 
              <telerik:GridViewDataColumn Header="Name" 
                                          DataMemberBinding="{Binding Name}" /> 
              <telerik:GridViewDataColumn Header="Created" 
                                          DataMemberBinding="{Binding Created}" 
                                          Width="200" /> 
            </telerikGridView:GridViewDataControl.Columns> 
          </telerikGridView:GridViewDataControl> 
        </DataTemplate> 
      </telerik:RadGridView.HierarchyChildTemplate> 
    </telerik:RadGridView>

Not all the rows in my gridview have child tables. Therefore I used the PreviewDataRecordCreate event to create the child tables where needed. This piece of code is in the constructor of my Silverlight control:

MyGrid.TableDefinition.PreviewDataRecordCreate += (sender, e) => { 
  Company c = (Company)e.Data; 
  if (!c.HasChildren) return
  GridViewTableDefinition t = new GridViewTableDefinition() { Relation = new PropertyRelation("Children") }; 
  e.ChildTableDefinitions.Add(t); 
  e.IsExpandableRecord = true
};

The grid looks exactly what it should look like, I can expand some of the rows while some other rows are not expandable. Nevertheless, I got stuck when trying to implement double-click. Here is another piece of code from the constructor of my control:

Mouse.AddMouseUpHandler(MyGrid, (sender, args) => { 
    if (args.ClickCount <= 1) return
    /* More code here... */ 
});

The event is fired when I double-click a top-level item in the gridview, but clicking an item in the inner table has no effect.

I also tried catching the MouseLeftButtonUp event of the GridViewDataControl that defines the inner table, but this event was never fired as well.

I really need to implement the double-click functionality... Any help is greatly appreciated.

Regards,
Jakub Zika

4 Answers, 1 is accepted

Sort by
0
Jakub
Top achievements
Rank 1
answered on 09 Oct 2009, 09:22 AM
Well... I apologize for being so impatient but... Does anybody have a solution for my problem?

I'm sure there is a ridiculously easy way to access the mouse events in a child grid, I just can't seem to find it...
0
Accepted
Kaloyan
Telerik team
answered on 09 Oct 2009, 03:13 PM
Hi Jakub,

Try adding the Mouse.AddMouseUpHandler to the Loaded GridView Row:
MyGrid.RowLoaded += new System.EventHandler<Telerik.Windows.Controls.GridView.RowLoadedEventArgs>(MyGrid_RowLoaded);
 
void MyGrid_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
        {
            Mouse.AddMouseUpHandler(e.Row, MouseUpHandler);
        }
 
private void MouseUpHandler(object sender, MouseButtonEventArgs e)
        {
            if (e.ClickCount <= 1) return;
            /* More code here... */
 
            MessageBox.Show("Double click");
        }


Best wishes,
Kaloyan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Jakub
Top achievements
Rank 1
answered on 23 Oct 2009, 09:51 AM
Thanks a lot Kaloyan, this solution works. However, I have another question.

Is there a simple way to find out which row in any of the child grids is selected (if any)?
0
Accepted
Milan
Telerik team
answered on 27 Oct 2009, 04:55 PM
Hello Jakub,

You can traverse all child grids and get access to their selected items:

private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
    var childGrids = this.clubsGrid.ChildrenOfType<GridViewExpandableRow>();
      
    foreach (var childGrid in childGrids)
    {
        var selectedItem = childGrid.ChildDataControls[0].SelectedItem;
    }
}


Best wishes,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Jakub
Top achievements
Rank 1
Answers by
Jakub
Top achievements
Rank 1
Kaloyan
Telerik team
Milan
Telerik team
Share this question
or