Tree View

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jakki
    New Member
    • Dec 2007
    • 5

    Tree View

    Is it possible to show the Treeview in a list box
  • harshadd
    New Member
    • Dec 2007
    • 180

    #2
    A list box can have multiple coloumns But yiu ca not use it as a tree, why you want a list box when tree is available? Both are designed for diff purpose...

    rgds
    Harshad Dandekar

    Comment

    • jakki
      New Member
      • Dec 2007
      • 5

      #3
      Tank you.. for your reply..

      Comment

      • jakki
        New Member
        • Dec 2007
        • 5

        #4
        i want to populate a data from a data base..

        i wrote a code for webapplication aspx.cs.. which is perfectly work's
        code is

        protected void Page_Load(objec t sender, EventArgs e)
        {
        if (!Page.IsPostBa ck)
        {
        PopulateRootLev el();
        }
        }
        //select ParentId, GroupName,(sele ct count(*) FROM tree WHERE SubGroup=sc.Par entId) SubGroup,SubGro up FROM tree sc where ParentId=@paren tID
        private void PopulateRootLev el()
        {
        SqlConnection objConn = new SqlConnection(" Data Source=CDTECHPR O2\\SQLEXPRESS; Initial Catalog=Image;I ntegrated Security=True") ;
        SqlCommand objCommand = new SqlCommand("sel ect ParentId,GroupN ame,(select count(*) FROM tree WHERE SubGroup=sc.Par entId) childnodecount FROM tree sc where SubGroup IS NULL", objConn);
        SqlDataAdapter da = new SqlDataAdapter( objCommand);
        DataTable dt = new DataTable();
        da.Fill(dt);
        PopulateNodes(d t, TreeView1.Nodes );
        }

        private void PopulateNodes(D ataTable dt, TreeNodeCollect ion nodes)
        {
        foreach (DataRow dr in dt.Rows)
        {
        TreeNode tn = new TreeNode();
        tn.Text = dr["GroupName"].ToString();
        tn.Value = dr["ParentId"].ToString();
        nodes.Add(tn);
        //If node has child nodes, then enable on-demand populating
        tn.PopulateOnDe mand = ((int)dr["childnodecount "] > 0);
        }
        }

        private void PopulateSubLeve l(int parentid, TreeNode parentNode)
        {
        SqlConnection objConn = new SqlConnection(" Data Source=CDTECHPR O2\\SQLEXPRESS; Initial Catalog=Image;I ntegrated Security=True") ;
        SqlCommand objCommand = new SqlCommand("sel ect ParentId,GroupN ame,(select count(*) FROM tree " + "WHERE SubGroup=sc.Par entId) childnodecount FROM tree sc where SubGroup=@SubGr oup", objConn);
        objCommand.Para meters.Add("@Su bGroup", SqlDbType.Int). Value = parentid;
        SqlDataAdapter da = new SqlDataAdapter( objCommand);
        DataTable dt = new DataTable();
        da.Fill(dt);
        PopulateNodes(d t, parentNode.Chil dNodes);
        }

        protected void TreeView1_TreeN odePopulate(obj ect sender, TreeNodeEventAr gs e)
        {
        int s = int.Parse(e.Nod e.Value);
        PopulateSubLeve l(s, e.Node);
        }




        but it should not work in C# windows application...


        PopulateOnDeman d insted of what method what method i am going to use to dinamically populate a data... and this event is also not alaliable..

        protected void TreeView1_TreeN odePopulate(obj ect sender, TreeNodeEventAr gs e)

        Comment

        Working...