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

Trouble with RadGridView

0 Answers 19 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 1
Joe asked on 06 Nov 2013, 09:00 PM
Hello,

I have a RadGridView on a user control, which is switched in/out via a ContentControl. The view model behind the grid is a singleton instance, and will be reused.

When the Content property of the ContentControl is changed, a new view is created as it should, however the grid nulls out the SelectedItem property, which then changes the view model underneath when this view/view model goes out of scope. Why does this occur?

I would like to be able to switch this view back in and display the selected item when the user comes back to it, which should be possible, but the grid changes the view model when unbinding.
<UserControl x:Class="InventoryView"
 
 
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 
 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 
             xmlns:tools="ViewModels.Tools;assembly=ViewModels"
 
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
 
             xmlns:conv="clr-namespace:Views.Converters"
 
             xmlns:views="clr-namespace:Views"
 
             mc:Ignorable="d"
 
             d:DesignHeight="700" d:DesignWidth="1000">
 
      
 
    <Grid d:DataContext="{d:DesignInstance Type=tools:InventoryViewModel, IsDesignTimeCreatable=True}">
 
        <Grid.ColumnDefinitions>
 
            <ColumnDefinition />
 
            <ColumnDefinition Width="5"/>
 
            <ColumnDefinition Width="2*" />
 
        </Grid.ColumnDefinitions>
 
          
 
        <TabControl Grid.Column="0">
 
            <TabControl.Items>
 
                <TabItem Header="Networks">
 
                    <!--<DataGrid ItemsSource="{Binding Networks}" SelectedItem="{Binding SelectedNetwork}"></DataGrid>-->
 
                    <telerik:RadGridView
 
                        ItemsSource="{Binding Networks}"
 
                        AutoGenerateColumns="False"
 
                        AlternationCount="1"
 
                        GridLinesVisibility="None"
 
                        CanUserDeleteRows="False"
 
                        CanUserInsertRows="False"
 
                        RowIndicatorVisibility="Collapsed"
 
                        SelectedItem="{Binding SelectedNetwork}">
 
                          
 
                        <telerik:RadGridView.Columns>
 
                            <telerik:GridViewDataColumn
 
                                Header="Name"
 
                                UniqueName="Name"
 
                                Width="100"
 
                                DataMemberBinding="{Binding Name}"/>
 
                              
 
                            <telerik:GridViewDataColumn
 
                                Header="Type"
 
                                UniqueName="Type"
 
                                Width="100"
 
                                DataMemberBinding="{Binding IsPhysical, Converter={StaticResource NetworkTypeConverter} }"/>
 
                              
 
                            <telerik:GridViewDataColumn
 
                                Header="Owner"
 
                                UniqueName="Owner"
 
                                Width="100"
 
                                DataMemberBinding="{Binding ContactName}"/>
 
                        </telerik:RadGridView.Columns>
 
                    </telerik:RadGridView>
 
                </TabItem>
 
    </Grid>
 
</UserControl>

<!-- placeholder for main content area view -->
<ContentControl Grid.Row="1"
                Content="{Binding SelectedToolViewModel}"
                ContentTemplateSelector="{Binding Source={StaticResource SelectedToolTemplateSelector}}" />


No answers yet. Maybe you can help?

Tags
GridView
Asked by
Joe
Top achievements
Rank 1
Share this question
or