I'm trying out a TreeListView. I have a context menu that allows a user to
delete an item. This doesn't seem to work if the item is a child of another
item. The algorithm is basically:
object c = treeListView.SelectedObject;
object p = treeListView.GetParent(c);
treeListView.RemoveObject(c);
p.RemoveChild(c); // the object keeps it's own internal list of its children
treeListView.RefreshObject(p);
So, basically remove the selected object and update it's parent. During the
refresh of the parent, the GetChildrenGetter delegate is called, and it indeed
returns a an empty list (no children), yet the child item is never removed.
Is this because the child item is selected and thus stays cached or something?
I'm wondering if I should unselect the child item before removing it. Ideally
I would be able to get the index of the item to be removed and then select the
item at index-1 after the removal (if I can get it to actually remove the
item).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Turns out the removing is working fine, but I have a different problem: the
select rectangle for an item label is wrong, so when I right-click an item to
display the context menu, no item is actually selected (so nothing is
removed).
I've done something to cause the select rectangle for the item labels to be
wrong, but haven't a clue what it could be. The plus buttons to expand items
are operating correctly, it's just that clicking on the item text is not
working properly.
In a root item, I can click about 5 pixels to the right of the label and it
selects the item.
In a first-level child, I can click on the label except on the last character
and it selects the item.
In a second-level child, I can only select the item by clicking in the left
half of the label.
In a third-level child, I can only select the item by clicking on the first
character.
On a fourth-level child, I cannot select the item by clicking on the label,
but clicking to the left of the plus sign selects the item.
Etc., etc.
Any ideas what I might have done wrong to get the offsets for the select
rectangles to be calculated incorrectly?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm trying out a TreeListView. I have a context menu that allows a user to
delete an item. This doesn't seem to work if the item is a child of another
item. The algorithm is basically:
object c = treeListView.SelectedObject;
object p = treeListView.GetParent(c);
treeListView.RemoveObject(c);
p.RemoveChild(c); // the object keeps it's own internal list of its children
treeListView.RefreshObject(p);
So, basically remove the selected object and update it's parent. During the
refresh of the parent, the GetChildrenGetter delegate is called, and it indeed
returns a an empty list (no children), yet the child item is never removed.
Is this because the child item is selected and thus stays cached or something?
I'm wondering if I should unselect the child item before removing it. Ideally
I would be able to get the index of the item to be removed and then select the
item at index-1 after the removal (if I can get it to actually remove the
item).
Turns out the removing is working fine, but I have a different problem: the
select rectangle for an item label is wrong, so when I right-click an item to
display the context menu, no item is actually selected (so nothing is
removed).
I've done something to cause the select rectangle for the item labels to be
wrong, but haven't a clue what it could be. The plus buttons to expand items
are operating correctly, it's just that clicking on the item text is not
working properly.
In a root item, I can click about 5 pixels to the right of the label and it
selects the item.
In a first-level child, I can click on the label except on the last character
and it selects the item.
In a second-level child, I can only select the item by clicking in the left
half of the label.
In a third-level child, I can only select the item by clicking on the first
character.
On a fourth-level child, I cannot select the item by clicking on the label,
but clicking to the left of the plus sign selects the item.
Etc., etc.
Any ideas what I might have done wrong to get the offsets for the select
rectangles to be calculated incorrectly?
Doh!
From TreeListViewDragDrop sample:
// Remember: TreeListViews must have a small image list assigned to them.
// If they do not, the hit testing will be wildly off