本文整理汇总了C#中System.Windows.Forms.TreeView.CollapseAll方法的典型用法代码示例。如果您正苦于以下问题:C# TreeView.CollapseAll方法的具体用法?C# TreeView.CollapseAll怎么用?C# TreeView.CollapseAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.TreeView
的用法示例。
在下文中一共展示了TreeView.CollapseAll方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SelectNode2Level
/// <summary>
/// 设置TreeView选中节点
/// </summary>
/// <param name="treeView"></param>
/// <param name="selectStr">选中节点文本</param>
public static void SelectNode2Level(TreeView treeView, string selectStr)
{
treeView.CollapseAll();
treeView.Visible = true;
treeView.Focus();
for (int i = 0; i < treeView.Nodes.Count; i++)
{
if (treeView.Nodes[i].Text == selectStr)
{
treeView.SelectedNode = treeView.Nodes[i];//选中
treeView.SelectedNode.Checked = true;
return;
}
for (int j = 0; j < treeView.Nodes[i].Nodes.Count; j++)
{
if (treeView.Nodes[i].Nodes[j].Text == selectStr)
{
treeView.SelectedNode = treeView.Nodes[i].Nodes[j];//选中
treeView.SelectedNode.Checked = true;
treeView.Nodes[i].Expand();//展开父级
return;
}
}
}
}
示例2: CollapseAll_NoNodes
public void CollapseAll_NoNodes ()
{
TreeView tv = new TreeView ();
tv.CollapseAll ();
}
示例3: favList_ItemDrag
private void favList_ItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e)
{
focusedTreeView = (e.Item as TreeNode).TreeView;
focusedTreeView.CollapseAll();
DoDragDrop(e.Item, DragDropEffects.Move);
}
示例4: collapseAll
public static void collapseAll(TreeView oTreeView)
{
oTreeView.CollapseAll();
}
示例5: ClearTreeview
internal static void ClearTreeview(TreeView tv)
{
try
{
tv.SuspendLayout();
for (var i = 0; i < tv.Nodes.Count; i++)
{
var subs = tv.Nodes[i].Nodes;
for (var j = 0; j < subs.Count; j++)
{
subs[j].Text = string.Empty;
}
}
tv.CollapseAll();
}
catch (Exception e)
{
LogHelper.Dump(e);
}
finally
{
tv.ResumeLayout();
}
}
示例6: Initialize
//.........这里部分代码省略.........
try
{
m_oMenuService.AddCommand(m_oNewCmdPaste);
}
catch
{
}
TreeViewDesigner.MenuAdded = true;
}
m_oTreeView.Invalidate();
#region action menus
#region node menu
m_oActionMenuNode = new ActionMenuNative();
m_oActionMenuNode.Width = 170;
m_oActionMenuNode.Title = "Node Action Menu";
ActionMenuGroup oMenuGroup = m_oActionMenuNode.AddMenuGroup("Editing");
oMenuGroup.Expanded = true;
m_oActionMenuNode.AddMenuItem(oMenuGroup, "Add Node");
m_oActionMenuNode.AddMenuItem(oMenuGroup, "Delete Node");
m_oActionMenuNode.AddMenuItem(oMenuGroup, "Add Panel");
m_oActionMenuNode.AddMenuItem(oMenuGroup, "-");
m_oActionMenuNode.AddMenuItem(oMenuGroup, "Clear Content");
m_oActionMenuNode.AddMenuItem(oMenuGroup, "Delete TreeView");
m_oActionMenuNode.AddMenuItem(oMenuGroup, "-");
m_oActionMenuNode.AddMenuItem(oMenuGroup, "Copy");
m_oActionMenuNode.AddMenuItem(oMenuGroup, "Paste");
m_oActionMenuNode.AddMenuItem(oMenuGroup, "-");
m_oActionMenuNode.AddMenuItem(oMenuGroup, "Properties");
oMenuGroup = m_oActionMenuNode.AddMenuGroup("Arranging");
m_oActionMenuNode.AddMenuItem(oMenuGroup, "Expand");
m_oActionMenuNode.AddMenuItem(oMenuGroup, "Collapse");
m_oActionMenuNode.AddMenuItem(oMenuGroup, "Move Top");
m_oActionMenuNode.AddMenuItem(oMenuGroup, "Move Bottom");
m_oActionMenuNode.AddMenuItem(oMenuGroup, "Move Up");
m_oActionMenuNode.AddMenuItem(oMenuGroup, "Move Down");
m_oActionMenuNode.AddMenuItem(oMenuGroup, "Move Left");
m_oActionMenuNode.AddMenuItem(oMenuGroup, "Move Right");
oMenuGroup = m_oActionMenuNode.AddMenuGroup("Color Schemes");
m_oActionMenuNode.AddMenuItem(oMenuGroup, "Default");
m_oActionMenuNode.AddMenuItem(oMenuGroup, "Forest");
m_oActionMenuNode.AddMenuItem(oMenuGroup, "Gold");
m_oActionMenuNode.AddMenuItem(oMenuGroup, "Ocean");
m_oActionMenuNode.AddMenuItem(oMenuGroup, "Rose");
m_oActionMenuNode.AddMenuItem(oMenuGroup, "Silver");
m_oActionMenuNode.AddMenuItem(oMenuGroup, "Sky");
m_oActionMenuNode.AddMenuItem(oMenuGroup, "Sunset");
m_oActionMenuNode.AddMenuItem(oMenuGroup, "Wood");
m_oActionMenuNode.ItemClick += new ActionMenuNative.ItemClickEventHandler(this.OnActionMenuNodeItemClicked);
#endregion
#region TreeView menu
m_oActionMenuTreeView = new ActionMenuNative();
m_oActionMenuTreeView.Width = 170;
m_oActionMenuTreeView.Title = "TreeView Action Menu";
oMenuGroup = m_oActionMenuTreeView.AddMenuGroup("Editing");
oMenuGroup.Expanded = true;
m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Add Node");
m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Color Scheme Picker...");
m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "-");
m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Clear Content");
m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Delete TreeView");
m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "-");
m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Copy");
m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Paste");
m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "-");
m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Properties");
oMenuGroup = m_oActionMenuTreeView.AddMenuGroup("Arranging");
m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Expand All");
m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Collapse All");
oMenuGroup = m_oActionMenuTreeView.AddMenuGroup("Layout");
m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Bring to Front");
m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Send to Back");
m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Align to Grid");
m_oActionMenuTreeView.AddMenuItem(oMenuGroup, "Lock Controls");
m_oActionMenuTreeView.ItemClick += new ActionMenuNative.ItemClickEventHandler(this.OnActionMenuTreeViewItemClicked);
#endregion
#endregion
// enable the drag drop operations
m_oTreeView.AllowDrop = true;
this.EnableDragDrop(true);
m_oTreeView.CollapseAll();
m_oSelector.SelectionService = m_oSelectionService;
m_oSelector.TreeView = m_oTreeView;
}
}
示例7: AddTreeToControls
/// <summary>
/// Adds a TreeView object to the list of controls.
/// </summary>
/// <param name="tv">The TreeView object to be added.</param>
public void AddTreeToControls(TreeView tv)
{
RemoveTreeFromControls(tv);
tv.Dock = DockStyle.Fill;
tv.Location = new Point(0, 45);
tv.Size = new Size(352, 294);
tv.ImageList = treeViewImages;
tv.CollapseAll();
Controls.Add(tv);
Controls.SetChildIndex(tv, 0);
}
示例8: ExpandCollapseStateTest
public void ExpandCollapseStateTest ()
{
TreeView treeView = new TreeView ();
TreeNode node1 = new TreeNode ("node1");
TreeNode node2 = new TreeNode ("node2");
TreeNode node1sub1 = new TreeNode ("node1 - sub1");
TreeNode node1sub2 = new TreeNode ("node1 - sub2");
node1.Nodes.Add (node1sub1);
node1.Nodes.Add (node1sub2);
TreeNode node1sub1sub1 = new TreeNode ("node1 - sub1 - sub1");
node1sub1.Nodes.Add (node1sub1sub1);
treeView.Nodes.AddRange (new TreeNode [] {
node1,
node2});
treeView.CollapseAll ();
IRawElementProviderFragmentRoot provider = (IRawElementProviderFragmentRoot)
GetProviderFromControl (treeView);
IRawElementProviderFragmentRoot node1Provider = (IRawElementProviderFragmentRoot)
provider.Navigate (NavigateDirection.FirstChild);
IRawElementProviderFragmentRoot node2Provider = (IRawElementProviderFragmentRoot)
node1Provider.Navigate (NavigateDirection.NextSibling);
IRawElementProviderFragmentRoot node1sub1Provider = (IRawElementProviderFragmentRoot)
node1Provider.Navigate (NavigateDirection.FirstChild);
IRawElementProviderFragmentRoot node1sub2Provider = (IRawElementProviderFragmentRoot)
node1sub1Provider.Navigate (NavigateDirection.NextSibling);
IRawElementProviderFragmentRoot node1sub1sub1Provider = (IRawElementProviderFragmentRoot)
node1sub1Provider.Navigate (NavigateDirection.FirstChild);
VerifyTreeNodePatterns (provider, node1Provider, node1);
VerifyTreeNodePatterns (provider, node2Provider, node2);
VerifyTreeNodePatterns (provider, node1sub1Provider, node1sub1);
VerifyTreeNodePatterns (provider, node1sub2Provider, node1sub2);
VerifyTreeNodePatterns (provider, node1sub1sub1Provider, node1sub1sub1);
IExpandCollapseProvider node1ExpandCollapse = (IExpandCollapseProvider)
node1Provider.GetPatternProvider (ExpandCollapsePatternIdentifiers.Pattern.Id);
IExpandCollapseProvider node2ExpandCollapse = (IExpandCollapseProvider)
node2Provider.GetPatternProvider (ExpandCollapsePatternIdentifiers.Pattern.Id);
IExpandCollapseProvider node1sub1ExpandCollapse = (IExpandCollapseProvider)
node1sub1Provider.GetPatternProvider (ExpandCollapsePatternIdentifiers.Pattern.Id);
IExpandCollapseProvider node1sub2ExpandCollapse = (IExpandCollapseProvider)
node1sub2Provider.GetPatternProvider (ExpandCollapsePatternIdentifiers.Pattern.Id);
IExpandCollapseProvider node1sub1sub1ExpandCollapse = (IExpandCollapseProvider)
node1sub1sub1Provider.GetPatternProvider (ExpandCollapsePatternIdentifiers.Pattern.Id);
Assert.AreEqual (ExpandCollapseState.Collapsed,
node1ExpandCollapse.ExpandCollapseState);
Assert.AreEqual (ExpandCollapseState.LeafNode,
node2ExpandCollapse.ExpandCollapseState);
Assert.AreEqual (ExpandCollapseState.Collapsed,
node1sub1ExpandCollapse.ExpandCollapseState);
Assert.AreEqual (ExpandCollapseState.LeafNode,
node1sub2ExpandCollapse.ExpandCollapseState);
Assert.AreEqual (ExpandCollapseState.LeafNode,
node1sub1sub1ExpandCollapse.ExpandCollapseState);
TestProperty (node1Provider,
ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
ExpandCollapseState.Collapsed);
TestProperty (node2Provider,
ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
ExpandCollapseState.LeafNode);
TestProperty (node1sub1Provider,
ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
ExpandCollapseState.Collapsed);
TestProperty (node1sub2Provider,
ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
ExpandCollapseState.LeafNode);
TestProperty (node1sub1sub1Provider,
ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty,
ExpandCollapseState.LeafNode);
bridge.ResetEventLists ();
node1.Expand ();
AutomationPropertyChangedEventTuple propertyEventTuple =
bridge.GetAutomationPropertyEventFrom (node1Provider,
ExpandCollapsePatternIdentifiers.ExpandCollapseStateProperty.Id);
Assert.IsNotNull (propertyEventTuple,
"Expected property change event on node 1");
Assert.AreEqual (ExpandCollapseState.Collapsed,
propertyEventTuple.e.OldValue,
"Old value");
Assert.AreEqual (ExpandCollapseState.Expanded,
propertyEventTuple.e.NewValue,
"New value");
Assert.AreEqual (ExpandCollapseState.Expanded,
//.........这里部分代码省略.........
示例9: ExpandCollapseTest
public void ExpandCollapseTest ()
{
TreeView treeView = new TreeView ();
TreeNode node1 = new TreeNode ("node1");
TreeNode node2 = new TreeNode ("node2");
TreeNode node1sub1 = new TreeNode ("node1 - sub1");
TreeNode node1sub2 = new TreeNode ("node1 - sub2");
node1.Nodes.Add (node1sub1);
node1.Nodes.Add (node1sub2);
TreeNode node1sub1sub1 = new TreeNode ("node1 - sub1 - sub1");
node1sub1.Nodes.Add (node1sub1sub1);
treeView.Nodes.AddRange (new TreeNode [] {
node1,
node2});
treeView.CollapseAll ();
IRawElementProviderFragmentRoot provider = (IRawElementProviderFragmentRoot)
GetProviderFromControl (treeView);
IRawElementProviderFragmentRoot node1Provider = (IRawElementProviderFragmentRoot)
provider.Navigate (NavigateDirection.FirstChild);
IRawElementProviderFragmentRoot node2Provider = (IRawElementProviderFragmentRoot)
node1Provider.Navigate (NavigateDirection.NextSibling);
// IRawElementProviderFragmentRoot node1sub1Provider = (IRawElementProviderFragmentRoot)
// node1Provider.Navigate (NavigateDirection.FirstChild);
// IRawElementProviderFragmentRoot node1sub2Provider = (IRawElementProviderFragmentRoot)
// node1sub1Provider.Navigate (NavigateDirection.NextSibling);
// IRawElementProviderFragmentRoot node1sub1sub1Provider = (IRawElementProviderFragmentRoot)
// node1sub1Provider.Navigate (NavigateDirection.FirstChild);
IExpandCollapseProvider node1ExpandCollapse = (IExpandCollapseProvider)
node1Provider.GetPatternProvider (ExpandCollapsePatternIdentifiers.Pattern.Id);
IExpandCollapseProvider node2ExpandCollapse = (IExpandCollapseProvider)
node2Provider.GetPatternProvider (ExpandCollapsePatternIdentifiers.Pattern.Id);
// IExpandCollapseProvider node1sub1ExpandCollapse = (IExpandCollapseProvider)
// node1sub1Provider.GetPatternProvider (ExpandCollapsePatternIdentifiers.Pattern.Id);
// IExpandCollapseProvider node1sub2ExpandCollapse = (IExpandCollapseProvider)
// node1sub2Provider.GetPatternProvider (ExpandCollapsePatternIdentifiers.Pattern.Id);
// IExpandCollapseProvider node1sub1sub1ExpandCollapse = (IExpandCollapseProvider)
// node1sub1sub1Provider.GetPatternProvider (ExpandCollapsePatternIdentifiers.Pattern.Id);
Assert.IsFalse (node1.IsExpanded);
Assert.IsFalse (node2.IsExpanded);
Assert.IsFalse (node1sub1.IsExpanded);
Assert.IsFalse (node1sub2.IsExpanded);
Assert.IsFalse (node1sub1sub1.IsExpanded);
node1ExpandCollapse.Expand ();
// TODO: test winforms events?
Assert.IsTrue (node1.IsExpanded);
Assert.IsFalse (node2.IsExpanded);
Assert.IsFalse (node1sub1.IsExpanded);
Assert.IsFalse (node1sub2.IsExpanded);
Assert.IsFalse (node1sub1sub1.IsExpanded);
node1ExpandCollapse.Expand ();
Assert.IsTrue (node1.IsExpanded);
Assert.IsFalse (node2.IsExpanded);
Assert.IsFalse (node1sub1.IsExpanded);
Assert.IsFalse (node1sub2.IsExpanded);
Assert.IsFalse (node1sub1sub1.IsExpanded);
node1ExpandCollapse.Collapse ();
Assert.IsFalse (node1.IsExpanded);
Assert.IsFalse (node2.IsExpanded);
Assert.IsFalse (node1sub1.IsExpanded);
Assert.IsFalse (node1sub2.IsExpanded);
Assert.IsFalse (node1sub1sub1.IsExpanded);
node1ExpandCollapse.Collapse ();
Assert.IsFalse (node1.IsExpanded);
Assert.IsFalse (node2.IsExpanded);
Assert.IsFalse (node1sub1.IsExpanded);
Assert.IsFalse (node1sub2.IsExpanded);
Assert.IsFalse (node1sub1sub1.IsExpanded);
try {
node2ExpandCollapse.Expand ();
Assert.Fail ("Expected InvalidOperationException when Expanding a LeafNode");
} catch (InvalidOperationException) {
// Expected
}
try {
node2ExpandCollapse.Collapse ();
Assert.Fail ("Expected InvalidOperationException when Collapsing a LeafNode");
//.........这里部分代码省略.........