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

SelectedItem event not fired: RadGridView within DataTemplate of RadTreeListView

4 Answers 124 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Raul
Top achievements
Rank 1
Raul asked on 07 Oct 2014, 11:57 AM
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>

4 Answers, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 07 Oct 2014, 02:48 PM
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.

 
0
Raul
Top achievements
Rank 1
answered on 07 Oct 2014, 03:03 PM
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
0
Raul
Top achievements
Rank 1
answered on 08 Oct 2014, 01:20 PM
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










0
Yoan
Telerik team
answered on 10 Oct 2014, 12:51 PM
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.

 
Tags
GridView
Asked by
Raul
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Raul
Top achievements
Rank 1
Share this question
or