Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i fill tree view with account type then accounts under each type sometime it work sometimes it get tcp/ip network error

This is The Code For Filling The Tree

C#
// Accounts Types
    private void FillAccountsTypeTree()
    {
        try
        {
            Tv_Tree.Nodes.Clear();
            //Tv_TypeTree.Nodes.Add(new TreeNode("Products Tree", "-1"));
            FillAccountsTypeParentNodes();
            FillAccountsByType();
        }
        catch (Exception ex)
        { throw new Exception(ex.Message); }
    }
    private void FillAccountsTypeParentNodes()
    {
        try
        {
            List<accounttype> _list = new List<accounttype>();
            _list = _dbml.AccountTypes.Where(p => p.ParentTypeID == null && p.CompanyID.Contains(Ddl_Companies.SelectedValue)).ToList();
            if (_list.Count != 0)
            {
                foreach (AccountType row in _list)
                {
                    TreeNode tn = new TreeNode(row.AccountTypeID.ToString() + "--" + row.TypeName, row.AccountTypeID.ToString());
                    Tv_Tree.Nodes.Add(tn);
                    FillAccountsTypeChildNodes(tn, row.AccountTypeID);
                }
            }
        }
        catch (Exception ex)
        {
            ErrHandler.WriteError(ex.Message);
            throw new Exception(ex.Message);
        }
    }
    private void FillAccountsTypeChildNodes(TreeNode Parent, Int64 ID)
    {
        try
        {
            List<accounttype> _list = new List<accounttype>();
            _list = _dbml.AccountTypes.Where(p => p.ParentTypeID == ID && p.CompanyID.Contains(Ddl_Companies.SelectedValue)).ToList();
            if (_list.Count != 0)
            {
                foreach (AccountType row in _list)
                {
                    TreeNode tn = new TreeNode(row.AccountTypeID.ToString() + "--" + row.TypeName, row.AccountTypeID.ToString());
                    Parent.ChildNodes.Add(tn);
                    FillAccountsTypeChildNodes(tn, row.AccountTypeID);
                }
            }
        }
        catch (Exception ex)
        {
            ErrHandler.WriteError(ex.Message);
            throw new Exception(ex.Message);
        }
    }
    private void FillAccountsByType()
    {
        foreach (TreeNode Tn in Tv_Tree.Nodes)
        {
            FillAccountNodeByType(Tn);
            GetAccountsChildNodesByType(Tn);
            //if (Tn.ChildNodes.Count == 0)
            //{ FillAccountNode(Tn); }
            //else
            //{ GetAccountsChildNodes(Tn); }
        }
    }
    private void GetAccountsChildNodesByType(TreeNode Parent)
    {
        try
        {
            foreach (TreeNode tn in Parent.ChildNodes)
            {
                FillAccountNodeByType(tn);
                GetAccountsChildNodesByType(tn);
                //if (tn.ChildNodes.Count == 0)
                //{ FillAccountNode(tn); }
                //else { GetAccountsChildNodes(tn); }
            }
        }
        catch (Exception ex)
        {
            ErrHandler.WriteError(ex.Message);
            throw new Exception(ex.Message);
        }
    }
    private void FillAccountNodeByType(TreeNode Parent)
    {
        try
        {
            List<accounttree> _list = new List<accounttree>();
            _list = _dbml.AccountTrees.Where(p => p.AccountTypeID == Convert.ToInt64(Parent.Value) && p.CompanyID == Convert.ToInt32(Ddl_Companies.SelectedValue)).ToList();
            if (_list.Count != 0)
            {
                foreach (AccountTree row in _list)
                {
                    TreeNode tn = new TreeNode(row.AccountName, row.AccountID.ToString());
                    Parent.ChildNodes.Add(tn);
                }
            }
        }
        catch (Exception ex)
        { throw new Exception(ex.Message); }
    }
Posted
Updated 10-Jun-12 19:13pm
v2
Comments
Ganesan Senthilvel 11-Jun-12 1:13am    
Code format.
[no name] 11-Jun-12 1:26am    
i don't get what u want to say
Sandeep Mewara 11-Jun-12 2:18am    
Nothing. He formatted your code and is just trying to tell what he did.
Sandeep Mewara 11-Jun-12 2:18am    
At the time of formatting, there is a small textbox just below the question body area. You can put your comments there related to formatting.
Sandeep Mewara 11-Jun-12 2:19am    
Now, did you look for more in the error? TCP/IP network error - anything else to it? Any logs? Event logs?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900