Search code examples
c#.netwinformsobjectlistview

ObjectListView: select subitem programmatically


How can I select a subitem of an ObjectListView programmatically?

SelectObject() and SelectItem() work only with root items, not with subitems.


Solution

  • I solve this problem. It can be useful for anybody, who have similar problem. For this, I need to change a source code of control by next:

    Change access type for TreeModel property in TreeListView class from protected to public. After this I have access to manipulate Branch objects of TreeListView object. For example, to select any subitem of root element I write next code:

    var branch = tlvMain.TreeModel.GetBranch(tlvMain.SelectedObject);
    var children = branch.Children.Cast<SecurityObject>().ToList();
    tlvMain.SelectObject(children.SingleOrDefault(p=>p.Id == soft.Id));