/// <summary> /// Set a new <paramref name="model"/> to be displayed in the <see /// cref="ListView"/>. /// </summary> public void SetModel(TreeListViewModel <TNode> model) { _listView.BeginUpdate(); try { _currentModel = model; UpdateListView(); } finally { _listView.EndUpdate(); } }
public bool IsExpanded(TreeListViewModel <TNode> model, TNode node, string path) { bool savedState; if (_expandedStates.TryGetValue(path, out savedState)) { return(savedState); } return(model.IsNodeExpanded(node)); }
private static string MakeNodePath(TreeListViewModel <TNode> model, string path, TNode node) { var text = model.GetNodePathComponent(node).Replace('\\', '-'); if (string.IsNullOrEmpty(path)) { return(text); } return(path + "\\" + text); }
/// <summary> /// Create all list view items corresponding to all the properties and property groups /// that should be displayed in the list view. Children of property groups that are not /// expanded are skipped -- they will be created when the groups are expanded. /// </summary> private List <ListViewItem> CreateListViewItems(TreeListViewModel <TNode> model, ExpandedNodeState expandedNodeState) { var itemList = new List <ListViewItem>(); if (model == null) { return(itemList); } if (model.IsRootVisible()) { CreateListViewItem(itemList, expandedNodeState, "", 0, model, model.GetRootNode()); } else { Enumerable.Range(0, model.GetChildCount(model.GetRootNode())).ForEach(index => { CreateListViewItem(itemList, expandedNodeState, "", 0, model, model.GetChildAt(model.GetRootNode(), index)); }); } return(itemList); }
private void CreateListViewItem(List <ListViewItem> itemList, ExpandedNodeState expandedNodeState, string parentPath, int indent, TreeListViewModel <TNode> model, TNode node) { var propertyNodePath = MakeNodePath(model, parentPath, node); var item = new ListViewItem(); itemList.Add(item); // Add the item before (optional) recursive call // Add sub-properties recursively (if group) if (model.IsNodeExpandable(node)) { var isExpanded = expandedNodeState.IsExpanded(model, node, propertyNodePath); item.ImageIndex = isExpanded ? 1 : 0; if (isExpanded) { Enumerable.Range(0, model.GetChildCount(node)).ForEach(index => { CreateListViewItem(itemList, expandedNodeState, propertyNodePath, indent + 1, model, model.GetChildAt(node, index)); }); } } // Setup final item properties after recursion, in case property node // value, for example, was changed as a side effect of the recursive call. item.Text = model.GetNodeText(node); var subItemCount = model.GetNodeSubItemCount(node); for (var subItem = 0; subItem < subItemCount; subItem++) { item.SubItems.Add(model.GetNodeSubItemAt(node, subItem)); } item.Tag = new ListViewItemTag(node, propertyNodePath); item.IndentCount = indent; }
/// <summary> /// Remove the current <see cref="TreeNodeCollection"/> and remove all entries /// displayed in the <see cref="ListView"/>. /// </summary> public void Clear() { _listView.Items.Clear(); _currentModel = null; }