Telerik RadTreeListView : Attaching event in rows

1.3k views Asked by At

I'm using telerik radgridview in my WPF app

 <telerik:RadTreeListView Grid.Row="1" Grid.ColumnSpan="2"
              Name="WorkPreferenceTreeView"
              AutoGenerateColumns="false"
              IsReadOnly="True"
              ItemsSource="{Binding ItemsSource, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Views:WorkPreferenceSelectorView}}}"
              RowIndicatorVisibility="Collapsed"
              SelectedItem="{Binding SelectedItem, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Views:WorkPreferenceSelectorView}}}" 
              ScrollViewer.HorizontalScrollBarVisibility="Hidden">

            <TelerikNavigation:RadContextMenu.ContextMenu>
                <TelerikNavigation:RadContextMenu x:Name="RadContextMenu" />
            </TelerikNavigation:RadContextMenu.ContextMenu>

            <telerik:RadTreeListView.ChildTableDefinitions>
                <telerik:TreeListViewTableDefinition  ItemsSource="{Binding ItemPreferences}"  />
            </telerik:RadTreeListView.ChildTableDefinitions>

            <telerik:RadTreeListView.Columns>

                <telerik:GridViewDataColumn MinWidth="200" Width="*" CellTemplate="
              {StaticResource ItemPreferenceskPreferenceCellTemplate}" Header="Preference" IsFilterable="false"
ShowFieldFilters="false" Name="A" />

And Im attaching an event on the control

  private void InitializeControl()
    {
        WorkPreferenceTreeView.MouseDoubleClick += (WorkPreferenceTreeView_MouseDoubleClick);
     }

Now my problem is the MouseDoubleClick event fires whenever I double click ANYWHERE in the radtreelistview (even in the Scroll Bar) where I just want it to fire when a selected item or row is double clicked. I'm wondering if I can just attach the MouseDoubleClick even in the selected item or each of the rows but I have no luck of finding way to do that. Any suggestion?

1

There are 1 answers

0
Dargos On

in your example, you did attached the event on the grid itself.

in fact you need to attach the event on the Row !

you can do it with RowStyle

(in this example, double click will toggle the IsExpanded row property)

<telerik:RadTreeListView ... >
     <telerik:RadTreeListView.RowStyle>
          <Style TargetType="telerik:TreeListViewRow">
               <EventSetter
                    Event="MouseDoubleClick"
                    Handler="HandleRowDoubleClick" />
          </Style>
     </telerik:RadTreeListView.RowStyle>
</telerik:RadTreeListView> 

and the code behind

public void HandleRowDoubleClick(object sender, RoutedEventArgs e)
{
    var row = sender as Telerik.Windows.Controls.GridView.GridViewRow;
    row.IsExpanded = !row.IsExpanded;
}

enjoy :)