I have tried to use the SelectionChanged event to accomplish what I want. I am successfully able to expand the parent row to expose the children rows and am able to add\remove children records from the tree's SelectedItems collection just fine.
I'm just having issues with disabling\enabling the selection column based on the property value (Required in this case) of the CatalogProduct which is bound to the tree. Even when the column appears to be disabled, I can still click on the checkbox and, of course, the column background is shaded gray when what I
really just want the checkbox to be disabled. Here is my code:
public
void
CatalogProductsSelectionChanged(
object
sender, SelectionChangeEventArgs e) {
var tree = (RadTreeListView) sender;
if
(e.AddedItems.Count > 0) {
var item = e.AddedItems[0];
var parent = (CatalogProduct) item;
//if children exist, expand hierarchy in tree control
if
(parent.ChildrenCatalogProducts.Count > 0) {
tree.ExpandHierarchyItem(item);
//find row corresponding to child and add to tree's SelectedItems
//collection. Disable selectcolumn if child
//has Required property set to true
foreach
(var child
in
parent.ChildrenCatalogProducts) {
var row = tree.ItemContainerGenerator.ContainerFromItem(child)
as
TreeListViewRow;
tree.SelectedItems.Add(child);
if
(row !=
null
) {
row.Cells[0].IsEnabled = !child.Required;
}
}
}
}
if
(e.RemovedItems.Count > 0)
{
var item = e.RemovedItems[0];
var parent = (CatalogProduct)item;
//if children exist, collapse hierarchy in tree control
if
(parent.ChildrenCatalogProducts.Count > 0) {
tree.CollapseHierarchyItem(item);
//Remove child item from Tree's SelectedItems and find
//row corresponding to child and enable its select column
foreach
(var child
in
parent.ChildrenCatalogProducts) {
var row = tree.ItemContainerGenerator.ContainerFromItem(child)
as
TreeListViewRow;
tree.SelectedItems.Remove(child);
if
(row !=
null
) {
row.Cells[0].IsEnabled =
true
;
}
}
}
}
}
I know that the ItemContainerGenerator method to grab the rows is not the way to go but I can't figure out an alternative.
Any advice?