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.
I have one parent with 2 children, i.e.
- Component ....Parent
Earnings ....child
Deductions ....child
I want the Earnings child to show all results from a U_PD_description field where U_PD_type = "Earnings", i.e
- Component ....Parent
Earnings ....child
Housing Allowance
Mobile Phone Allowance
Mileage Allowance
Deductions ....child
and likewise for deductions. I have the following code for formload:
private void frm_earn_deduct_setup_Load(object sender, EventArgs e)
{
// Get service instance
var earnDeductMasterService = Program.Kernel.Get<IEarnDeductMasterService>();
//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 => 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 => 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<IEarnDeductMasterService>().GetAllEarnDeductMasters().ToList();
}
Can anyone show me an example on how to populate say the earnings subtree in treeView1?