当前位置:编程学习 > C#/ASP.NET >>

求助关于menustrip和Treeview绑定显示的问题,急!

我现在的需求是这样的

1、WINFORM中根据menustrip已有的层次结构,在Treeview显示出对于的结构,这个需求已经做好了!

2、在1的基础,当我将menustrip的几个选项的visiable属性设置为false时,Treeview上也不会显示,这个需求上有问题!!

我加断点跟踪后发现,明明我大多数menustrip选项的visiable属性都是设置为Ture的,但程序运行起来就变为false了,紧急

求教,谢谢!!


我的代码如下:

private void ShowTree(TreeNode Pnode, ToolStripMenuItem itemcol)
        {
            for (int i = 0; i < itemcol.DropDownItems.Count; i++)
            {
               
                if (itemcol.DropDownItems[i].Visible ==true  )
                {
                    TreeNode Node = new TreeNode();
                    Node.Text = itemcol.DropDownItems[i].Text.Trim();
                    Node.Name = itemcol.DropDownItems[i].Name;
                    Pnode.Nodes.Add(Node);
                    ShowTree(Node, (ToolStripDropDownItem)itemcol.DropDownItems[i]);
                }
                else
                {
 
                }
            }
        }

        private void ShowTree(TreeNode Pnode, ToolStripDropDownItem itemcol)
        {
            for (int i = 0; i < itemcol.DropDownItems.Count; i++)
            {
                
                if (itemcol.DropDownItems[i].Text.Trim() != "-" && itemcol.DropDownItems[i].Text.Trim() != "" )
                {
                    TreeNode Node = new TreeNode();
                        Node.Text = itemcol.DropDownItems[i].Text.Trim();
                        Pnode.Nodes.Add(Node);
                        ShowTree(Node, (ToolStripDropDownItem)itemcol.DropDownItems[i]);
                }
            }
        }

        private void frmMain_Load(object sender, EventArgs e)
        {

            ToolStripMenuItem itemcol=(ToolStripMenuItem) this.menuStripMain.Items[0];
            textBox2 .Text  =Convert .ToString ( itemcol.DropDownItems.Count);
            textBox1.Text =Convert .ToString ( itemcol.DropDownItems[0].Visible ) ;
            textBox3.Text = itemcol.DropDownItems[1].Text;
            try
            {
                for (int i = 0; i < this.menuStripMain.Items.Count; i++)
                {
                    TreeNode node = new TreeNode();
                   
                    if (this.menuStripMain.Items[i].Visible == true)
                    {
                        node.Text = this.menuStripMain.Items[i].Text.Trim();
                        node.Name = this.menuStripMain.Items[i].Name;
                        this.trvMain.Nodes.Add(node);
                        try
                        {
                            if (!this.menuStripMain.Items[i].GetType().ToString().ToUpper().Equals("ToolStripSeparator".ToUpper()))
                            {
                                ShowTree(node, (ToolStripMenuItem)this.menuStripMain.Items[i]);
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                    else
                    {

                    }
                }
                this.trvMain .ExpandAll();
            }
            catch (Exception ex)
            {
                MessageBox.Show("加载信息出错,错误信息如下:\n" + ex.Message);
            }
        }
--------------------编程问答-------------------- F11单步看看各项的值
--------------------编程问答--------------------
引用 1 楼 wuyq11 的回复:
F11单步看看各项的值


我就是F11调试的啊 --------------------编程问答-------------------- 有高手能解答下嘛? --------------------编程问答-------------------- 我就是想问的是为什么我没有设置默认的visiable属性,程序运行后会成false的 --------------------编程问答-------------------- 求助各位高手啊 --------------------编程问答-------------------- 帮你发个颜色,没颜色太难看了。。。
private void ShowTree(TreeNode Pnode, ToolStripMenuItem itemcol)
  {
  for (int i = 0; i < itemcol.DropDownItems.Count; i++)
  {
    
  if (itemcol.DropDownItems[i].Visible ==true )
  {
  TreeNode Node = new TreeNode();
  Node.Text = itemcol.DropDownItems[i].Text.Trim();
  Node.Name = itemcol.DropDownItems[i].Name;
  Pnode.Nodes.Add(Node);
  ShowTree(Node, (ToolStripDropDownItem)itemcol.DropDownItems[i]);
  }
  else
  {
  
  }
  }
  }

  private void ShowTree(TreeNode Pnode, ToolStripDropDownItem itemcol)
  {
  for (int i = 0; i < itemcol.DropDownItems.Count; i++)
  {
    
  if (itemcol.DropDownItems[i].Text.Trim() != "-" && itemcol.DropDownItems[i].Text.Trim() != "" )
  {
  TreeNode Node = new TreeNode();
  Node.Text = itemcol.DropDownItems[i].Text.Trim();
  Pnode.Nodes.Add(Node);
  ShowTree(Node, (ToolStripDropDownItem)itemcol.DropDownItems[i]);
  }
  }
  }

  private void frmMain_Load(object sender, EventArgs e)
  {

  ToolStripMenuItem itemcol=(ToolStripMenuItem) this.menuStripMain.Items[0];
  textBox2 .Text =Convert .ToString ( itemcol.DropDownItems.Count);
  textBox1.Text =Convert .ToString ( itemcol.DropDownItems[0].Visible ) ;
  textBox3.Text = itemcol.DropDownItems[1].Text;
  try
  {
  for (int i = 0; i < this.menuStripMain.Items.Count; i++)
  {
  TreeNode node = new TreeNode();
    
  if (this.menuStripMain.Items[i].Visible == true)
  {
  node.Text = this.menuStripMain.Items[i].Text.Trim();
  node.Name = this.menuStripMain.Items[i].Name;
  this.trvMain.Nodes.Add(node);
  try
  {
  if (!this.menuStripMain.Items[i].GetType().ToString().ToUpper().Equals("ToolStripSeparator".ToUpper()))
  {
  ShowTree(node, (ToolStripMenuItem)this.menuStripMain.Items[i]);
  }
  }
  catch (Exception ex)
  {
  MessageBox.Show(ex.Message);
  }
  }
  else
  {

  }
  }
  this.trvMain .ExpandAll();
  }
  catch (Exception ex)
  {
  MessageBox.Show("加载信息出错,错误信息如下:\n" + ex.Message);
  }
  }


问题的保姆,帖子的管家——《Csdn收音机》!
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,