/// <summary> /// Populate the contents of the node that is about to be expanded. /// </summary> /// <param name="e">the arguments giving the node to be expanded</param> protected override void OnBeforeExpand(TreeViewCancelEventArgs e) { FileSystemTreeNode node = e.Node as FileSystemTreeNode; if (node != null && node.IsExpandable) { BeginUpdate(); node.Nodes.Clear(); try { node.DoExpand(); node.SelectedImageIndex = node.ImageIndex = node.DisplayIcon; } catch (Exception ex) { node.Text = node.DisplayName + " : " + ex.Message; node.IsExpandable = true; e.Cancel = true; } finally { EndUpdate(); } } base.OnBeforeExpand(e); }
/// <summary> /// Called after a node is collapsed, used to remove the contents of the node /// as node contents are generated when opened. /// </summary> /// <param name="e"></param> protected override void OnAfterCollapse(TreeViewEventArgs e) { FileSystemTreeNode node = e.Node as FileSystemTreeNode; if (node != null) { node.IsExpandable = true; node.SelectedImageIndex = node.ImageIndex = node.DisplayIcon; } }