Hi Telerik!
I have a code here...
private void OnMenuItemClicked(object sender, RoutedEventArgs args)
{
RadRoutedEventArgs e = args as RadRoutedEventArgs;
RadMenuItem item = e.OriginalSource as RadMenuItem;
RadTreeView it = sender as RadTreeView;
DataItem tem = (DataItem)it.SelectedItem;
DataItem itemToAdd = new DataItem()
{
Text = "New Section",
ParentID = tem.ID,
Docuname = tem.Docuname,
ID = treeitemCollection[treeitemCollection.Count - 1].ID++,
RemoveCommand = new DelegateCommand((p) => { treeitemCollection.RemoveItem(p); }),
AddCommand = new DelegateCommand((p) => { treeitemCollection.AddItem(p); })
};
tem.Children.Add(itemToAdd);
MessageBox.Show(""+tem.Children.Count());
ReportsServiceClient client = new ReportsServiceClient();
client.InsertSectionContextAsync("New Section", tem.ID, tem.Docuname);
client.CloseAsync();
Dispatcher.BeginInvoke(() =>
{
RadTreeViewItem currentItem = it.ContainerFromItemRecursive(itemToAdd) as RadTreeViewItem;
if (currentItem != null)
{
currentItem.IsInEditMode = true;
currentItem.Focus();
}
else
MessageBox.Show("currentItem is NULL");
});
}
This code will add new item in radtreeview with new item in edit mode. It works fine when I add an item if the parent has already a child. But, when I add an item to the parent with no child, a null reference exception occurs. Do you have any idea whats wrong with it?
I have a code here...
private void OnMenuItemClicked(object sender, RoutedEventArgs args)
{
RadRoutedEventArgs e = args as RadRoutedEventArgs;
RadMenuItem item = e.OriginalSource as RadMenuItem;
RadTreeView it = sender as RadTreeView;
DataItem tem = (DataItem)it.SelectedItem;
DataItem itemToAdd = new DataItem()
{
Text = "New Section",
ParentID = tem.ID,
Docuname = tem.Docuname,
ID = treeitemCollection[treeitemCollection.Count - 1].ID++,
RemoveCommand = new DelegateCommand((p) => { treeitemCollection.RemoveItem(p); }),
AddCommand = new DelegateCommand((p) => { treeitemCollection.AddItem(p); })
};
tem.Children.Add(itemToAdd);
MessageBox.Show(""+tem.Children.Count());
ReportsServiceClient client = new ReportsServiceClient();
client.InsertSectionContextAsync("New Section", tem.ID, tem.Docuname);
client.CloseAsync();
Dispatcher.BeginInvoke(() =>
{
RadTreeViewItem currentItem = it.ContainerFromItemRecursive(itemToAdd) as RadTreeViewItem;
if (currentItem != null)
{
currentItem.IsInEditMode = true;
currentItem.Focus();
}
else
MessageBox.Show("currentItem is NULL");
});
}
This code will add new item in radtreeview with new item in edit mode. It works fine when I add an item if the parent has already a child. But, when I add an item to the parent with no child, a null reference exception occurs. Do you have any idea whats wrong with it?