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

NullReferenceException With SelectedItem

0 Answers 60 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 11 Oct 2012, 05:46 PM

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);
 
}


 

 

 

 

 

No answers yet. Maybe you can help?

Tags
TreeListView
Asked by
Rob
Top achievements
Rank 1
Share this question
or