none
How to populate tree view from data table RRS feed

  • Question

  • see this is my xml from where i store data into data table

    <?xml version="1.0" standalone="yes"?>
    <EstimateConfigs>
      <EstimateConfig>
        <ActSection>Consensus Model</ActSection>
        <ActLineItem>Net Revenue</ActLineItem>
        <ActBroker>3A-P1</ActBroker>
        <ActPeriod>2010 FYA</ActPeriod>
        <Select>True</Select>
      </EstimateConfig>
      <EstimateConfig>
        <ActSection>Consensus Model</ActSection>
        <ActLineItem>Net Revenue</ActLineItem>
        <ActBroker>3A-P1</ActBroker>
        <ActPeriod>2011 FYA</ActPeriod>
        <Select>True</Select>
      </EstimateConfig>
        <EstimateConfig>
        <ActSection>Consensus Model</ActSection>
        <ActLineItem>Net Revenue</ActLineItem>
        <ActBroker>P1</ActBroker>
        <ActPeriod>2010 FYA</ActPeriod>
        <Select>True</Select>
      </EstimateConfig>
      <EstimateConfig>
        <ActSection>Consensus Model</ActSection>
        <ActLineItem>Net Revenue</ActLineItem>
        <ActBroker>P1</ActBroker>
        <ActPeriod>2011 FYA</ActPeriod>
        <Select>True</Select>
      </EstimateConfig>
      </EstimateConfigs>

    i want to create first node in tree view with all distinct ActBroker from datatable and each broker will have sub node like ActLineItem which will be also distinct as per ActBroker. i need to fetch ActLineItem as per ActBroker wise. how to do it

    please guide me how to find out first unique ActBroker from data table and later each ActBroker node will have unique ActLineItem which is associated with broker. please help me. thanks

    • Moved by CoolDadTx Thursday, September 12, 2019 2:01 PM Winforms related
    Wednesday, September 11, 2019 3:03 PM

All replies

  • For the base logic (which is not against your data) should give you are start.

    protected void PopulateTreeView (TreeNodeCollection parentNode, int parentID, DataTable folders)
    {   
        foreach (DataRow folder in folders.Rows)
        {
            if (Convert.ToInt32(folder["parentID"]) == parentID)
            {
                String key = folder["ID"].ToString();
                String text = folder["title"].ToString();
                TreeNodeCollection newParentNode = parentNode.Add(key, text).Nodes;
                PopulateTreeView(newParentNode, Convert.ToInt32(folder["ID"]), folders);                    
            }
        }
    }

    Original source

    http://cstruter.com/blog/247


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, September 11, 2019 8:00 PM
    Moderator
  • Hi Sudip-inn

    Thank you for posting here.

    For you question, could you provide a tree view image like the following picture?

    I also noted that you only mentioned ActBroker and ActLineItem nodes. I wan to know if it means that you don't need other nodes.

    Best Regards,

    Jack



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.



    Thursday, September 12, 2019 2:06 AM
  • yes i need only these node ActBroker and ActLineItem

    first i need to find unique ActBroker and if unique ActBroker found say 5 then 5 node will be added and each node will have ActLineItem associated with ActBroker that i need to add under ActBroker. if still not clear what i am saying or trying to achieve then please let me know...then i will discuss the same again. thanks

    Sunday, September 15, 2019 7:47 PM
  • Hi Sudip_inn

    Thanks for the feedback.

    >>if unique ActBroker found say 5 then 5 node will be added

    I am not understand this sentence. How do this say 5?

    Besides, I hope that you could provide the tree view image. You could draw an image to express your meaning.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, September 16, 2019 6:13 AM