同上

解决方案 »

  1.   

    private void treeViewContact_AfterSelect(object sender, TreeViewEventArgs e)
    {
    TreeNode node = e.Node;
    try
    {
    if(!this.IsLeafNode(node))
    {
    //根节点
    for(int i = 0; i < node.Nodes.Count; i ++)
    {
    node.Nodes[i].Checked = node.Checked;
    }
    }
    else
    {
    string s_ID = e.Node.Tag.ToString();
    string s_Name = e.Node.Text; if (e.Node.Checked)
    {
        //添加联系人
    bool flagInc = false;
                                
    //记录是否重复
    flagInc = this.is_Exist(s_ID, this.hashtableContact);
    if (!flagInc) 
    {
    this.hashtableContact.Add(s_ID, s_Name);
    }
    this.printPerson();
    }
    else
    {
    //删除联系人
    IDictionaryEnumerator myEnumerator = this.hashtableContact.GetEnumerator();
    while ( myEnumerator.MoveNext() )
    {
    if(myEnumerator.Key.Equals(s_ID))
    {
                                    hashtableContact.Remove(s_ID);
    break;
    }
    }
    this.printPerson();
    }
    }
    }
    catch (Exception ex)
    {
    m_Logger.Debug("异常错误 !", ex);
    throw ex;
    }
    } /// <summary>
    /// 判断是否是根节点
    /// </summary>
    /// <param name="node"></param>
    /// <returns></returns>
    public bool IsLeafNode (TreeNode node)
    {
    return (node.Nodes.Count == 0);
    }