SelectedItem event not fired: RadGridView within DataTemplate of RadTreeListView

5 posts, 0 answers
  1. Raul
    Raul avatar
    20 posts
    Member since:
    Apr 2014

    Posted 07 Oct 2014 Link to this post

    Hello,

    I have a GridView in the DataTemplate of a TreeListView. Sometimes (quite often) the SelectedItem event of the GridView is not fired. I can see that the items are visually correctly selected but sometimes only the SelectedItem event of the TreeListView is fired (checked by an output within both SelectedItem properties).

    Best Regards
    Raul


    <UserControl x:Class="PrimeTime.Views.Employees.EmployeeWorkdayErrorSelectionView"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                 xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
                 xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" 
                 xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                 mc:Ignorable="d" Height="504" Width="400">
     
        <UserControl.Resources>
            <ResourceDictionary>
                <DataTemplate x:Key="ErrorWorkdaysTemplate">
                    <telerik:RadGridView ItemsSource="{Binding WorkdayErrors}" EnableRowVirtualization="False" IsReadOnly="True" SelectionMode="Single"
                                         AutoGenerateColumns="False" ShowGroupPanel="False" ShowColumnHeaders="False"
                                         ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                                         CanUserInsertRows="False" CanUserDeleteRows="False" CanUserSortColumns="False"
                                         IsSynchronizedWithCurrentItem="True"  IsFilteringAllowed="False"
                                         SelectedItem="{Binding SelectedWorkdayError, Mode=TwoWay}">
     
                        <telerik:RadGridView.Columns>
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding WorkdayDate}" Header="Day" Width="70"/>
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding ErrorMessage}" Header="Error" Width="Auto"/>
                        </telerik:RadGridView.Columns>
                    </telerik:RadGridView>
                </DataTemplate>
            </ResourceDictionary>
        </UserControl.Resources>
     
        <telerik:RadTreeListView x:Name="tlv_EmployeeSelection" EnableRowVirtualization="False" ItemsSource="{Binding Childs}"
                                 AutoGenerateColumns="False" AutoExpandItems="True" IsReadOnly="True"
                                 RowDetailsVisibilityMode="VisibleWhenSelected" SelectionMode="Single"
                                 IsFilteringAllowed="False" CanUserDeleteRows="False" CanUserInsertRows="False"
                                 RowDetailsTemplate="{StaticResource ErrorWorkdaysTemplate}"
                                 SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
     
            <telerik:RadTreeListView.ChildTableDefinitions>
                <telerik:TreeListViewTableDefinition ItemsSource="{Binding Childs}"/>
            </telerik:RadTreeListView.ChildTableDefinitions>
     
            <telerik:RadTreeListView.Columns>
                <telerik:GridViewDataColumn UniqueName="Name" DataMemberBinding="{Binding Name}" Header="Name" Width="*"/>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding PersonnelNumber}" Header="Number" Width="70"/>
            </telerik:RadTreeListView.Columns>
        </telerik:RadTreeListView>
    </UserControl>
  2. Yoan
    Admin
    Yoan avatar
    1070 posts

    Posted 07 Oct 2014 Link to this post

    Hello Raul,

    Do you have BindingExpression errors in your Output? You can try to specify valid source for the binding. For an example: 
    <telerik:RadGridView ItemsSource="{Binding Players}" EnableRowVirtualization="False" IsReadOnly="True" SelectionMode="Single"
                                         AutoGenerateColumns="False" ShowGroupPanel="False" ShowColumnHeaders="False"
                                         ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                                         CanUserInsertRows="False" CanUserDeleteRows="False" CanUserSortColumns="False"
                                         IsSynchronizedWithCurrentItem="True"  IsFilteringAllowed="False"
                                         SelectedItem="{Binding SelectedItem, Mode=TwoWay,Source={StaticResource MyViewModel}}">


    Regards,
    Yoan
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Raul
    Raul avatar
    20 posts
    Member since:
    Apr 2014

    Posted 07 Oct 2014 in reply to Yoan Link to this post

    Hello Yoan,

    there are no binding errors. The SelectedItem event is fired for some items, but not all. Therefore the binding is ok and the items are all loaded and displayed. Only problem is that the initial SelectedItem event is not fired. If I switch between the items of the GridView then the event which previously was not fired works as intended.
    So the problem is when the node of the TreeListView is selected it shows the DataTemplate and automatically selects the first item but sometimes forgets to fire the SelectedItem event.

    Greetings
    Raul
  5. Raul
    Raul avatar
    20 posts
    Member since:
    Apr 2014

    Posted 08 Oct 2014 in reply to Raul Link to this post

    Hello,

    there is no error. The system remembers the SelectedItem of each GridView, so after reopening it no event is fired.

    But I still have a problem because I want to know if another branch has been opened and which DataGrid item is now selected. Changing the DataContext of the SelectedItem property so that all DataGrids use the same DataContext didn't solve the problem.

    Any idea how this can be done?

    Greetings 
    Raul










  6. Yoan
    Admin
    Yoan avatar
    1070 posts

    Posted 10 Oct 2014 Link to this post

    Hi Raul,

    In order to achieve this functionality, you can try to implement a logic for selecting only a single row in every grid. You can check this GitHub example for a reference. You  can also check this forum thread.

    As a side note - Although GitHub is a very well-known platform we saw a better and easier approach for reviewing our examples developing our SDK Samples Browser. You can also use it to review the examples.


    Regards,
    Yoan
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for WPF is Visual Studio 2017 Ready