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

SelectedItem Object Reference not set

1 Answer 42 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Francois asked on 06 Aug 2009, 10:43 AM
Working with: Version 2009.1.526.35

Trying to set SelectedItem.

<telerik:RadGridView AutoGenerateColumns="False"
                             SelectedItem="{Binding Path=Entity, Mode=TwoWay}" IsReadOnly="False"
            ItemsSource="{Binding Path=Entities}"

In my constructor of my model I create a instance of Entity (Selected) and a List of Entities(ItemSource).

When I run, I get a Object Reference not Set... exception.
The same code works fine with a ListBox.

1 Answer, 1 is accepted

Sort by
Rossen Hristov
Telerik team
answered on 10 Aug 2009, 10:30 AM
Hello Francois,

I have tried to reproduce this behavior with the latest version but I could not. Here is part of my sample project:

<Window x:Class="TicketID_233145_SelectedItemBinding.Window1" 
    Title="Window1" Height="300" Width="300"
            <RowDefinition Height="Auto"/> 
            <RowDefinition Height="Auto"/> 
        <Button Content="Display Selected Club"  
            ItemsSource="{Binding Path=Clubs}" 
            SelectedItem="{Binding Path=SelectedClub, Mode=TwoWay}"

using System.Collections.Generic; 
using System.Linq; 
using System.Windows; 
namespace TicketID_233145_SelectedItemBinding 
    /// <summary> 
    /// Interaction logic for Window1.xaml 
    /// </summary> 
    public partial class Window1 : Window 
        public Window1() 
            this.SelectedClub = this.Clubs.Where(c => c.Name == "Chelsea").FirstOrDefault(); 
            this.clubsGrid.DataContext = this
        public IEnumerable<Club> Clubs 
            get { return Club.ClubsDataSource; } 
        public Club SelectedClub { getset; } 
        private void OnDisplaySelected(object sender, RoutedEventArgs e) 
            MessageBox.Show("The currently selected club is " + this.SelectedClub.Name); 

I have attached the whole project. Can you run it on your end and tell me the results. Also, can you check whether this will be resolved if you upgrade to the latest internal build.

All the best,
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Asked by
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Share this question