Friday, 22 February 2013

Data Show in TreeView

 I want to show the data in a tree view.but thjat treeview is on the text box.




This is the treeview.

 void filltrv()
        {
            try
            {
                trvCategory.Nodes.Clear();
                var n = (from y in ERPManagement.GetInstance.GetAllMenus()
                         where y.Parent_Menu_ID == 0
                         select y).ToList();
                for (i = 0; i < n.Count; i++)
                {
                    TreeNode tn = new TreeNode();
                    tn.Tag = n[i].Menu_ID.ToString();
                    tn.Text = n[i].Menu_Name.ToString();
                    trvCategory.Nodes.Add(tn);
                }
                for (i = 0; i < trvCategory.Nodes.Count; i++)
                {
                    var nn = (from y in ERPManagement.GetInstance.GetAllMenus()
                              where y.Parent_Menu_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].Menu_ID.ToString();
                            tn1.Text = nn[j].Menu_Name.ToString();
                            trvCategory.Nodes[i].Nodes.Add(tn1);
                        }

                    }
                }
            }
            catch (Exception ex)
            {
            }
        }

  private void TxtParentMenu_Enter(object sender, EventArgs e)
        {
            try
            {
                filltrv();
                trvCategory.Visible = true;
            }
            catch (Exception ex)
            {
            }
        }

private void trvCategory_AfterSelect(object sender, TreeViewEventArgs e)
        {
            try
            {
                int x=trvCategory.SelectedNode.Level;
                if (x == 0)
                {
                    TxtParentMenu.Text = trvCategory.SelectedNode.Text;
                    ParentMenuID = Convert.ToInt32(trvCategory.SelectedNode.Tag);
                }
                else
                {
                    TxtParentMenu.Text = trvCategory.SelectedNode.Parent.Text;
                    ParentMenuID = Convert.ToInt32(trvCategory.SelectedNode.Parent.Tag);
                }
               
               
                trvCategory.Visible = false;
                CmbSequence.Enabled = true;
                BindSequence();
            }
            catch (Exception ex)
            {
            }
        }
StoreProcedure
ALTER procedure [Inventory].[KC_SelectMenu1]
 as
 begin

  WITH Menu1(Menu_ID,Parent_Menu_Name)
     AS
     (SELECT Menu_ID,Menu_Name
      FROM Inventory.MST_Menu WHERE Is_Active=1 )
   
     SELECT a.Menu_ID,a.Menu_Name,a.Menu_Text,
a.Parent_Menu_ID,a.Sequence,a.Icon,a.Page_Name,a.Status,b.Parent_Menu_Name,
      Created_On,Created_By,
     Modified_On,Modified_By,Is_Active,Is_Deleted
     FROM Inventory.MST_Menu a
     LEFT OUTER JOIN Menu1 b
     ON a.Parent_Menu_ID=b.Menu_ID  WHERE Is_Active=1 AND Is_Deleted=0

 end

Database Design

No comments:

Post a Comment