Monday, 3 December 2012

tree view in c#.net

   private void frmCategories_Load(object sender, EventArgs e)
        {
var n = (from y in obj1.GetCategoryData() where y.Parent_Category_ID == 0 select y).ToList();
            for (i = 0; i < n.Count; i++)
            {
                TreeNode tn = new TreeNode();
                tn.Tag=n[i].Category_ID.ToString();
                tn.Text=n[i].Category_Name.ToString();
                trvCategory.Nodes.Add(tn);
            }
            for (i = 0; i < trvCategory.Nodes.Count; i++)
            {
                var nn = (from y in obj1.GetCategoryData() where y.Parent_Category_ID ==Convert.ToInt32(trvCategory.Nodes[i].Tag.ToString()) select y).ToList();
                if (nn.Count > 0)
                {
                    for (int j = 0; j < nn.Count; j++)
                    {
                        TreeNode tn1 = new TreeNode();
                        tn1.Tag = nn[j].Category_ID.ToString();
                        tn1.Text = nn[j].Category_Name.ToString();
                        trvCategory.Nodes[i].Nodes.Add(tn1);
                    }
                   
                }
            }
}
 private void trvCategory_AfterSelect(object sender, TreeViewEventArgs e)
        {
            txtDescription.Text = trvCategory.SelectedNode.Tag.ToString();
        }

No comments:

Post a Comment