/// <summary> /// Event handler for the tree view KeyDown event. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.Windows.Forms.KeyEventArgs"/> instance containing the event data.</param> private void HandleConfigurationTreeViewKeyDown(object sender, KeyEventArgs e) { ListItemTreeNode listNode = this._configurationTreeView.SelectedNode as ListItemTreeNode; if (listNode != null) { if (e.Control) { if (e.KeyCode == Keys.Up) { // // Move the list item up // listNode.MoveUp(); e.Handled = true; } else if (e.KeyCode == Keys.Down) { // // Move the list item down // listNode.MoveDown(); e.Handled = true; } } else if (e.KeyCode == Keys.Delete) { // // Delete the list item // listNode.RemoveItem(); e.Handled = true; } } }
/// <summary> /// Event handler for the property grid PropertyValueChanged event. /// </summary> /// <param name="s">The sender.</param> /// <param name="e">The <see cref="System.Windows.Forms.PropertyValueChangedEventArgs"/> instance containing the event data.</param> private void HandlePropertyGridPropertyValueChanged(object s, PropertyValueChangedEventArgs e) { ListItemTreeNode listItemTreeNode = this._configurationTreeView.SelectedNode as ListItemTreeNode; if (listItemTreeNode != null) { listItemTreeNode.UpdateText(); } }
/// <summary> /// Adds nodes for a list. /// </summary> /// <param name="listNode">The list node.</param> /// <param name="listProperty">The list property.</param> /// <param name="component">The component.</param> /// <param name="childList">The child list.</param> private void AddListTreeNodes( TreeNode listNode, PropertyDescriptor listProperty, object component, IList childList) { foreach (object listItem in childList) { TreeNode listItemNode = new ListItemTreeNode(listProperty, component, listItem); listNode.Nodes.Add(listItemNode); AddChildTreeNodes(listItemNode, listItem); } }
/// <summary> /// Refreshes nodes within a list property. /// </summary> /// <param name="listNode">The list node.</param> /// <param name="listProperty">The list property.</param> /// <param name="component">The component.</param> /// <param name="childList">The child list.</param> private void RefreshListTreeNodes(TreeNode listNode, PropertyDescriptor listProperty, object component, IList childList) { for (int itemIndex = 0; itemIndex < childList.Count; itemIndex++) { object listItem = childList[itemIndex]; ListItemTreeNode listItemNode = null; // // Look for an existing node for the list item // for (int nodeIndex = 0; nodeIndex < listNode.Nodes.Count; nodeIndex++) { ListItemTreeNode listItemNodeCandidate = listNode.Nodes[nodeIndex] as ListItemTreeNode; object listItemNodeValue = listItemNodeCandidate.ListItem; if (listItemNodeValue.Equals(listItem)) { listItemNode = listItemNodeCandidate; break; } } if (listItemNode == null) { // Create a new node listItemNode = new ListItemTreeNode(listProperty, component, listItem); listNode.Nodes.Add(listItemNode); AddChildTreeNodes(listItemNode, listItem); } else if (listItemNode.Index != itemIndex) { // Update the node position listNode.Nodes.Remove(listItemNode); listNode.Nodes.Insert(itemIndex, listItemNode); itemIndex = 0; } listItemNode.UpdateMenu(); } // Remove nodes that are no longer present in the list for (int nodeIndex = childList.Count; nodeIndex < listNode.Nodes.Count; nodeIndex++) { listNode.Nodes.RemoveAt(nodeIndex); nodeIndex--; } }