NullReferenceException With SelectedItem

1 posts, 0 answers
  1. Rob
    Rob avatar
    12 posts
    Member since:
    Apr 2012

    Posted 11 Oct 2012 Link to this post

    When I click on a row in my TreeListView, I get a NullReferenceException error in my SelectionChanged method:

    <telerik:RadTreeListView Name="equipmentTreeView" Margin="8" Background="Beige"
                         ItemsSource="{Binding FirstGeneration}"
                         telerik:StyleManager.Theme="Vista"  IsDragDropEnabled="True"
                         SelectionMode="Single"
                         SelectionUnit="FullRow"
                         SelectionChanged="equipmentTreeView_SelectionChanged"
                         IsSynchronizedWithCurrentItem="False"
                         AutoGenerateColumns="False" >
       
      <telerik:RadTreeListView.ChildTableDefinitions>
        <telerik:TreeListViewTableDefinition ItemsSource="{Binding Children}" />
      </telerik:RadTreeListView.ChildTableDefinitions>
      <telerik:RadTreeListView.Columns>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding TagName}"
                                    Header="{l:Translate ModuleEquipmentNavigator_ColumnHeaderTag}"
                                    Width="Auto"/>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Description}"
                                    Header="{l:Translate ModuleEquipmentNavigator_ColumnHeaderDesc}"
                                    Width="Auto"/>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding ImportedEquipmentType}"
                                    Header="{l:Translate ModuleEquipmentNavigator_ColumnHeaderIET}"
                                    Width="Auto"/>       
      </telerik:RadTreeListView.Columns>
    </telerik:RadTreeListView>

     

    public class AssetRowItem
    {
        public string TagName { get; set; }
        public string Description { get; set; }
        public string ImportedEquipmentType { get; set; }
    }



    private void equipmentTreeView_SelectionChanged(object sender, SelectionChangeEventArgs e)
    {
        AssetRowItem aRI = this.equipmentTreeView.SelectedItem as AssetRowItem;
     
        string message = string.Format("Tag Name: {0} \n Description: {1} \n Imported Equipment Type: {2}",
                                aRI.TagName,
                                aRI.Description,
                                aRI.ImportedEquipmentType);
        MessageBox.Show(message);
     
    }


     

     

     

     

     

Back to Top