日期:2014-05-18 浏览次数:21222 次
private void getTree(string outboundno, string pn, string custpo)
        {   
            __WMS_Tree[] trees = server.pickingTree_Search(outboundno, pn, custpo);
            if(trees!=null) 
            {
                treeNodeCtn = new TreeNode[trees.Length];
                for (int i=0; i<trees.Length; i++)
                {
                    //add ctn nodes
                    __WMS_Tree t = trees[i];
                    string ctnNo = t.cartonNo;
                   
                    string flag = t.carton_flag==null?"1":t.carton_flag;  
                    treeNodeCtn[i] = new TreeNode(ctnNo);
                    treeNodeCtn[i].Expand();  //这里展开不了下面的节点
                    if (Convert.ToInt32(flag)>=3)
                    {
                        Console.WriteLine("carton"+i+":"+flag+"$$$");
                           treeNodeCtn[i].Checked = true;     // 初始设置为选中状态没起作用 
                    }
                    
                    //add box nodes
                    __WMS_Box[] boxs = trees[i].boxSet;
                  
                    if(boxs.Length>0) 
                    {
                        treeNodeBox = new TreeNode[boxs.Length];
                        for (int j=0; j<boxs.Length; j++)
                        {
                            __WMS_Box b = boxs[j];
                            string boxNo = b.boxNo;
                            string box_flag = b.flag==null?"1":b.flag;
                            treeNodeBox[j] = new TreeNode(boxNo);
                        //    treeNodeBox[j].Expand = true ;
                            if (Convert.ToInt32(box_flag)>=3)
                            {
                                Console.WriteLine("box"+j+":"+flag+"######");
                                treeNodeBox[j].Checked = true ;
                            }
                            
                            treeNodeCtn[i].Nodes.Add(treeNodeBox[j]);
                        }
                    }
                    treeView1.Nodes.Add(treeNodeCtn[i]);
                    //add event handler
                    treeView1.AfterSelect += new TreeViewEventHandler(treeView1_AfterSelect);
                }
            }
        }
this.treeView1.ExpandAll();
------解决方案--------------------
good
------解决方案--------------------
treeNodeCtn[i].Checked = true;
是没错的
但是没有checkbox是不行的
而且,你的写法很怪异
------解决方案--------------------
treeView1.Nodes[i].Expand(); i 是符合你要求的 ,比如选中的节点
treeView1.Nodes[i].Checked = true; 打勾 。前提是 treeView1.CheckBoxes = true;
------解决方案--------------------
楼主的写法很奇怪(一般人都是一个node一个node实例化,像楼主这样一次实例化一个node数组再对数组中的node逐个实例化的写法实在少见),不过我用楼主的代码做了个测试,是没问题的。