Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. TreeView-Error

TreeView-Error

Scheduled Pinned Locked Moved C#
helpdata-structurestutorialquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    Udayaraju
    wrote on last edited by
    #1

    Here I am trying to fill the tree view category and subcategory wise..see the below |Benson and Hedges |Kings Gold Falke Beverages | |-Beers | |-Bell Lager 500 ML | |-CLUB PILSENER 500 ML | |-Juices | |-Apple Juice | |-Chikooo Juice |-Food | |-MeatProducts | |-GOAT MEAT | |-Fruits | |-APPLE GREEN | |-LOCAL ORANGES |-VegeTable | | |-BEETROOT | |-TOMATO FRESH I have tried the following code..but I am able to fill only one product under one sub category. Please help me out how to??initialize and fill the data into tree view

    foreach (DataRow row in table.Rows)
    {
    MainNode = new TreeNode(row.ItemArray[0].ToString());
    MainNode.Name = row.ItemArray[0].ToString();
    if (MainNode.Text == "")
    {
    //Stmts
    }

                    else
                    {
                        ChildNode = new TreeNode(row.ItemArray\[1\].ToString());
                        ChildNode.Name = row.ItemArray\[1\].ToString();
                        if (ChildNode.Text == "")
                        {
                            ChildNode = new TreeNode(row.ItemArray\[3\].ToString());
                            ChildNode.Name = row.ItemArray\[3\].ToString();
                            ChildNode.Tag = row.ItemArray\[2\].ToString();
                            if (!MainNode.Nodes.ContainsKey(ChildNode.Name))
                            {
                                MainNode.Nodes.Add(ChildNode);
                            } }
                        else
                        {
                            SubNode = new TreeNode(row.ItemArray\[3\].ToString());
                            SubNode.Name = row.ItemArray\[3\].ToString();
                            SubNode.Tag = row.ItemArray\[2\].ToString();
                            if (!ChildNode.Nodes.ContainsKey(SubNode.Name))
                            {
                                ChildNode.Nodes.Add(SubNode);
                            } }
                        if (!MainNode.Nodes.ContainsKey(ChildNode.Name))
                        {
                            MainNode.Nodes.Add(ChildNode);
                        }
                        else
                        {
    

    //Here I am unable to understand how to fill child nodes into mainnode
    //The below code is wrong
    for (int i = 0; i <= MainNode.Nodes.Count; i++)
    {

    X 1 Reply Last reply
    0
    • U Udayaraju

      Here I am trying to fill the tree view category and subcategory wise..see the below |Benson and Hedges |Kings Gold Falke Beverages | |-Beers | |-Bell Lager 500 ML | |-CLUB PILSENER 500 ML | |-Juices | |-Apple Juice | |-Chikooo Juice |-Food | |-MeatProducts | |-GOAT MEAT | |-Fruits | |-APPLE GREEN | |-LOCAL ORANGES |-VegeTable | | |-BEETROOT | |-TOMATO FRESH I have tried the following code..but I am able to fill only one product under one sub category. Please help me out how to??initialize and fill the data into tree view

      foreach (DataRow row in table.Rows)
      {
      MainNode = new TreeNode(row.ItemArray[0].ToString());
      MainNode.Name = row.ItemArray[0].ToString();
      if (MainNode.Text == "")
      {
      //Stmts
      }

                      else
                      {
                          ChildNode = new TreeNode(row.ItemArray\[1\].ToString());
                          ChildNode.Name = row.ItemArray\[1\].ToString();
                          if (ChildNode.Text == "")
                          {
                              ChildNode = new TreeNode(row.ItemArray\[3\].ToString());
                              ChildNode.Name = row.ItemArray\[3\].ToString();
                              ChildNode.Tag = row.ItemArray\[2\].ToString();
                              if (!MainNode.Nodes.ContainsKey(ChildNode.Name))
                              {
                                  MainNode.Nodes.Add(ChildNode);
                              } }
                          else
                          {
                              SubNode = new TreeNode(row.ItemArray\[3\].ToString());
                              SubNode.Name = row.ItemArray\[3\].ToString();
                              SubNode.Tag = row.ItemArray\[2\].ToString();
                              if (!ChildNode.Nodes.ContainsKey(SubNode.Name))
                              {
                                  ChildNode.Nodes.Add(SubNode);
                              } }
                          if (!MainNode.Nodes.ContainsKey(ChildNode.Name))
                          {
                              MainNode.Nodes.Add(ChildNode);
                          }
                          else
                          {
      

      //Here I am unable to understand how to fill child nodes into mainnode
      //The below code is wrong
      for (int i = 0; i <= MainNode.Nodes.Count; i++)
      {

      X Offline
      X Offline
      Xmen Real
      wrote on last edited by
      #2

      Problem is

      for (int i = 0; i <= MainNode.Nodes.Count; i++)
      { MainNode.Nodes.Add(ChildNode);
      }

      why this loop...you should learn about recursive methods ;)

      TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

      U 1 Reply Last reply
      0
      • X Xmen Real

        Problem is

        for (int i = 0; i <= MainNode.Nodes.Count; i++)
        { MainNode.Nodes.Add(ChildNode);
        }

        why this loop...you should learn about recursive methods ;)

        TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

        U Offline
        U Offline
        Udayaraju
        wrote on last edited by
        #3

        Recursive methods?? Please help me out with an example or an article..I have never worked on it??

        X 1 Reply Last reply
        0
        • U Udayaraju

          Recursive methods?? Please help me out with an example or an article..I have never worked on it??

          X Offline
          X Offline
          Xmen Real
          wrote on last edited by
          #4

          Link using stack http://www.google.com/search?hl=en&client=opera&rls=en&hs=D58&q=Recursive+methods+in+C%23&btnG=Search[^]

          TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups