Note that there are some explanatory texts on larger screens.

plurals
  1. POC# Populating a treeview from database results
    primarykey
    data
    text
    <p>I am learning the C# programming language and am making a payroll application add-on for SAP business One. I have never used a treeview before and wanted to know how one goes about populating the tree items from a database. I am using Visual Studio 2010 and Microsoft SQL Server 2008.</p> <p>I have one parent with 2 children, i.e.</p> <pre><code>- Component ....Parent Earnings ....child Deductions ....child </code></pre> <p>I want the Earnings child to show all results from a U_PD_description field where U_PD_type = "Earnings", i.e</p> <pre><code>- Component ....Parent Earnings ....child Housing Allowance Mobile Phone Allowance Mileage Allowance Deductions ....child </code></pre> <p>and likewise for deductions. I have the following code for formload:</p> <pre><code> private void frm_earn_deduct_setup_Load(object sender, EventArgs e) { // Get service instance var earnDeductMasterService = Program.Kernel.Get&lt;IEarnDeductMasterService&gt;(); //Query database for all records that have earnings var earnings = from ed in earnDeductMasterService.GetAllEarnDeductMasters() where ed.U_PD_type.Trim().Equals("Earnings".Trim(), StringComparison.CurrentCultureIgnoreCase) select ed; if (earnings.Any(x =&gt; x != null)) { //To populate subtree Earnings with U_PD_description results //.....some code here } else { //Nothing to populate } //............................................................................. //Query database for all records that have deductions var deductions = from ed in earnDeductMasterService.GetAllEarnDeductMasters() where ed.U_PD_type.Trim().Equals("Deductions".Trim(), StringComparison.CurrentCultureIgnoreCase) select ed; if (deductions.Any(x =&gt; x != null)) { //To populate subtree Deductions with U_PD_description results //.....some code here } else { //Nothing to populate } // Disable default items txt_amt_greater_than.Enabled = false; bindingNavigatorDeleteItem.Enabled = false; // Call service instance earnDeductMasterBindingSource.DataSource = Program.Kernel.Get&lt;IEarnDeductMasterService&gt;().GetAllEarnDeductMasters().ToList(); } </code></pre> <p>Can anyone show me an example on how to populate say the earnings subtree in treeView1?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload