TreeView 循环遍历选中的value

代码
  private void GetAllNodeText()
    {
        
foreach (TreeNode tn in _treeView1.Nodes)
        {
            
if (tn.Checked == false)
            {
                
if (string.IsNullOrEmpty(_operCode))
                {
                    _operCode 
+= tn.Value;
                }
                
else
                {
                    _operCode 
+= "," + tn.Value;
                }

            }
            
if (tn.ChildNodes.Count > 0)
            {
                
foreach (TreeNode tn1 in tn.ChildNodes)
                {
                    
if (tn1.Checked == false)
                    {
                        
if (string.IsNullOrEmpty(_operCode))
                        {
                            _operCode 
+= tn1.Value;
                        }
                        
else
                        {
                            _operCode 
+= "," + tn1.Value;
                        }
                    }

                }
            }

        }
    }
 
 
 _operCode 就是接收的选中的值 
 
 
2------------------将值赋给Treeview  
代码
 foreach (TreeNode tn in _treeView1.Nodes)
                        {
                            
for (int j = 0; j < strurl.Length; j++)
                            {
                                
if (tn.Value == strurl[j])
                                {
                                    tn.Checked 
= false;
                                }
                                
foreach (TreeNode tn1 in tn.ChildNodes)
                                {
                                    
if (tn1.Value == strurl[j])
                                    {
                                        tn1.Checked 
= false;
                                    }
                                }
                            }
                        }
 
//我存储的是规律的是  不选中的值存储在数据库 所以在我取出数据的时候 我先让我的Treeview 全部选中 然后将与数据库等同的值不选中 所以我tn.Checked = false;

 

 

 

posted @ 2010-03-22 17:30  不必太用力  阅读(547)  评论(0编辑  收藏  举报