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

Setting SelectedItem in GridView ineffective when inside collapsed RadExpander

9 Answers 67 Views
GridView
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 10 Jul 2012, 11:06 PM
Hello,

I have a RadGridView inside a RadExpander as follows:

<telerik:RadExpander Grid.Row="2" Grid.Column="0" IsExpanded="False" Margin="0,10,0,0">
    <telerik:RadExpander.Header>
        <TextBlock Text="{Binding ElementName=_this, Path=TargetStatistics.TargetCount, StringFormat=Targets ({0})}"/>
    </telerik:RadExpander.Header>
     
        <telerik:RadGridView x:Name="targetList" ItemsSource="{Binding Path=SensorDataBuffer.Targets}" AutoGenerateColumns="False" CanUserDeleteRows="False" CanUserInsertRows="False" IsReadOnly="True" IsFilteringAllowed="False" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Visible" RowIndicatorVisibility="Collapsed" SelectionMode="Single">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn Header="Timestamp" DataMemberBinding="{Binding Path=Timestamp, StringFormat=HH:mm:ss}"/>
                <telerik:GridViewDataColumn Header="Location" DataMemberBinding="{Binding Path=Location, Converter={StaticResource LocationConverter}}"/>
                <telerik:GridViewDataColumn Header="Confidence" DataMemberBinding="{Binding Path=Confidence, StringFormat=p0}"/>
                <telerik:GridViewDataColumn Header="Depth" DataMemberBinding="{Binding Path=Depth, Converter={StaticResource DistanceConverter}}"/>
                <telerik:GridViewDataColumn Header="Detected by" DataMemberBinding="{Binding Path=TargetDetectType.Enum}"/>
                <telerik:GridViewDataColumn Header="User action" DataMemberBinding="{Binding Converter={StaticResource TargetToUserActionConverter}}"/>
                <telerik:GridViewDataColumn Header="Status" DataMemberBinding="{Binding Converter={StaticResource TargetToCurrentStatusConverter}}"/>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
 
</telerik:RadExpander>

The SensorDaraBuffer.Targets that the RadGridView is bound to is a ReadOnlyObservableCollection<Target>.

Elsewhere in the same XAML file, I have bound the SelectedItem property of the RadGridView to a DependencyProperty in a UserControl named SensorDataView:

<local:SensorDataView x:Name="sensorDataView" SelectedTarget="{Binding ElementName=targetList, Path=SelectedItem, Mode=TwoWay}"/>

The SelectedTarget DependencyProperty is defined as follows:

public static DependencyProperty SelectedTargetProperty = DependencyProperty.Register("SelectedTarget", typeof(Target), typeof(SensorDataView), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnSelectedTargetChanged));

My problem is that when the window containing the RadExpander is first displayed (with the RadExpander collapsed) setting the SelectedItem property of the RadGridView does not cause the desired item to be selected. I have tried both setting the SelectedItem property directly on the GridView:
targetList.SelectedItem = target;

and by setting the SelectedTarget DependencyProperty:

sensorDataView.SelectedTarget = target;

I know that the selection of the desired item is not occurring because I have another control that is bound to the SelectedTarget DependencyProperty and that control does not give any visual indication of the selected target being changed. Also, my OnSelectedTargetChanged event handler in SensorDataView does not get called.

Once I expand the RadExpander via the UI and actually see the RadGridView, the setting of the SelectedItem, regardless of which way I do it, works as expected. I can also then collapse the RadExpander and the setting of the SelectedItem continues to work as expected.

I believe this is an issue with RadGridView because I replaced the RadGridView in the XAML with a ListView as follows:

<ListView Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="4" x:Name="targetList" ItemsSource="{Binding Path=SensorDataBuffer.Targets}" Margin="10,0,0,0">
    <ListView.View>
        <GridView>
            <GridViewColumn Header="Timestamp" DisplayMemberBinding="{Binding Path=Timestamp, StringFormat=HH:mm}"/>
            <GridViewColumn Header="Location" DisplayMemberBinding="{Binding Path=Location, Converter={StaticResource LocationConverter}}"/>
            <GridViewColumn Header="Confidence" DisplayMemberBinding="{Binding Path=Confidence, StringFormat=p0}"/>
            <GridViewColumn Header="Depth" DisplayMemberBinding="{Binding Path=Depth, Converter={StaticResource DistanceConverter}}"/>
            <GridViewColumn Header="Detection Type" DisplayMemberBinding="{Binding Path=TargetDetectType.Enum}"/>
            <GridViewColumn Header="Status" DisplayMemberBinding="{Binding Converter={StaticResource TargetToCurrentStatusConverter}}"/>
        </GridView>
    </ListView.View>
</ListView>

With the ListView, the setting of the SelectedItem works as expected from the very beginning when the RadExpander is collapsed and continues to work as I expand and collapse the RadExpander.

Does anybody have an idea what may be going here?

Thank you,

-- john

9 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 12 Jul 2012, 08:10 AM
Hello John,

Our latest internal build  contains a fix which I believe is related to your issue. It should be available for download in your account . Can you please give it a try . All you need to do is get the fresh dlls and reference them in your project.

Please let me know in case referencing the fresh  LIB binaries  does not fix it.

All the best,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
John
Top achievements
Rank 1
answered on 17 Jul 2012, 05:34 PM
Hello Pavel,

I downloaded RadControls_for_WPF_2012_2_0716_DEV_hotfix.zip from my account and tried the WPF40 Binaries contained therein. Unfortunately, they did not fix my problem.

Could you please look again for a solution to my problem.

Thank you,

-- john
0
Vera
Telerik team
answered on 20 Jul 2012, 04:14 PM
Hi John,

 
Will it be possible to open a support ticket and to send a simple runnable project demonstrating the issue? We will debug it on our side in order to see what is going wrong. Please take a look at this blog post on how to isolate a problem in a sample project.

Thank you in advice.

All the best,
Vera
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
John
Top achievements
Rank 1
answered on 20 Jul 2012, 10:59 PM
As requested, I have entered Support Ticket ID 567913. Please note that the Support Ticket entry web page would not let me select the appropriate GridView control version. The version I am using is 2012.2.0607.40.

-- john
0
Maya
Telerik team
answered on 23 Jul 2012, 08:13 AM
Hi John,

I would recommend you to count on bindings instead of setting directly SelectedItem since they could be reevaluated and the proper value will be set.
I am sending you the updated project illustrating a possible way to proceed. The exact implementation depends entirely on your exact requirements.  

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
John
Top achievements
Rank 1
answered on 23 Jul 2012, 04:15 PM
Hi Maya,

I'm sorry but your suggested use of binding via the new MyViewModel class does not solve my problem for several reasons:

1) I do not necessarily want just the selection of a Target in the targetList in the MainWindow to cause the selection of the corresponding Target in the targetList in the SubWIndow. That is why I use the MouseDoubleClick event to cause the selection in the SubWIndow. I understand I can stop this behavior by removing the binding to SelectedItem in targetList in MainWindow, but I don't know if this binding is crucial to your solution.

2) In my real application, I already have the SelectedItem property of the targetList in SubWIndow bound to another property. I left that out in my sample for simplification.

3) My initial problem of the selection in the SubWIndow not being effective when the RadExpander is initially not expanded still exists. To be clear, when I start the spplication and double-click target B in the MainWindow, I expect the SubWindow to be displayed (which it is) and I also expect the last line in that window to display "Selected target name: B" (which it is not). I also expect further double-clicking on other targets in the MainWindow to cause the "Selected target name: x" text in the SubWIndow to change. Instead, the SubWindow just displays "Selected target name:" until I expand the RadExpander.

Please let me know if you have any questions.

-- john
0
Maya
Telerik team
answered on 24 Jul 2012, 07:25 AM
Hi John,

It is not necessary to use the exact approach I suggested above, but rather to follow the idea of using bindings instead. Since RadGridView is not yet created if RadExpander is not expanded, setting SelectedItem will have no results (as you have already seen). Another possible way to go would be to save the selected item of the first grid in another property and update the value of the text below ('Selected target name: ") and the one of the SelectedItem on opening the expander.

All the best,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
John
Top achievements
Rank 1
answered on 24 Jul 2012, 03:43 PM
Hi Maya,

Okay, thank you for the clarification. Needless to say, it is disappointing that the RadGridView is not created until the first time the RadExpander is expanded. Especially since replacing the RadGridView with a ListView that contains a GridView works perfectly, as explained in my original post to this thread. Perhaps Telerik can consider changing this behavior of RadGridView?

Thank you for your help,

-- john
0
Maya
Telerik team
answered on 25 Jul 2012, 11:15 AM
Hi John,

The behavior you get between the two controls is caused by the difference when the data is loaded - in the case of RadGridView it is loaded when expanding it. The exact same behavior can be observed with DataGrid. 

All the best,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
John
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
John
Top achievements
Rank 1
Vera
Telerik team
Maya
Telerik team
Share this question
or