TreeView

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • LLM
    New Member
    • Apr 2007
    • 23

    #1

    TreeView

    I built a treeview from a datatable on a windows form, but I am not understanding fully. I could not find anywhere to tell it what the id was going to be. My now I am showing has an associated ID. How do I assign this ID no the child nodes and then how do I pull out the id of the child node they clicked on?

    Any help would be much appreciated.

    - Lisa
  • prabunewindia
    New Member
    • Mar 2007
    • 199

    #2
    i am not getting u correctly
    plz be clear lisa

    Originally posted by LLM
    I built a treeview from a datatable on a windows form, but I am not understanding fully. I could not find anywhere to tell it what the id was going to be. My now I am showing has an associated ID. How do I assign this ID no the child nodes and then how do I pull out the id of the child node they clicked on?

    Any help would be much appreciated.

    - Lisa

    Comment

    • LLM
      New Member
      • Apr 2007
      • 23

      #3
      Originally posted by prabunewindia
      hi lisa
      this is prabu here.
      i read ur query. but not clear to me.
      plz be clear. i also did the same i think.
      so i can clear u/

      Code:
                  // fill the tree node
                  foreach (DataRow row in dtData.Rows)
                  {
                      node = tvOffender.Nodes.Add(row["OffenderName"].ToString());
      
                      //get subs
                      daData2 = new OleDbDataAdapter("SELECT LastName + ', ' + FirstName + ' ' + MiddleName + '  (' + convert(varchar(10), InsertDateTime, 101) + ')' AS Name FROM Registration " +
                                      "WHERE ID = " + row["ID"].ToString() + "ORDER BY LastName, FirstName, MiddleName", strConnectionString);
                      daData2.Fill(dtData2);
                      foreach (DataRow row2 in dtData2.Rows)
                      {
                          child = node.Nodes.Add(row2["OffenderName"].ToString());
                      }
                  }
      I fill it like this. How do I assign the ID to my treeview and then grab it out when they click on it in the treeview to move to an edit page?

      Comment

      • LLM
        New Member
        • Apr 2007
        • 23

        #4
        foreach (DataRow row in dtData.Rows)
        {
        node = tvOffender.Node s.Add(row["Name"].ToString());


        foreach (DataRow row2 in dtData2.Rows)
        {
        child = node.Nodes.Add( row2["RegistrationID "].ToString(), row2["Name"].ToString());
        }
        }



        Can someone help? How do I get the ID of the selected node? tv.SelectedNode .value does not exist.. I am getting desperate!

        Comment

        • prabunewindia
          New Member
          • Mar 2007
          • 199

          #5
          hi lisa,
          here u given registrationID as TreeNode text property and Name as Value property. i think regID is int!

          code like this da,

          child = node.Nodes.Add( (string)row2["Name"], convert.ToInt32 (row2["RegistrationID "]));

          then
          get the regID while u selecting the node,

          RegID=Convert.T oInt32(tv.Selec tedNode.Value);


          plz be free and try don't get tension

          Originally posted by LLM
          foreach (DataRow row in dtData.Rows)
          {
          node = tvOffender.Node s.Add(row["Name"].ToString());


          foreach (DataRow row2 in dtData2.Rows)
          {
          child = node.Nodes.Add( row2["RegistrationID "].ToString(), row2["Name"].ToString());
          }
          }



          Can someone help? How do I get the ID of the selected node? tv.SelectedNode .value does not exist.. I am getting desperate!

          Comment

          Working...