我正在學習C#編程語言,並且正在爲SAP業務One製作薪資應用程序附加組件。我以前從未使用樹視圖,並想知道如何從數據庫填充樹項目。我使用Visual Studio 2010和Microsoft SQL Server 2008C#從數據庫結果中填充樹視圖
我有一個父有2個孩子,即
- Component ....Parent
Earnings ....child
Deductions ....child
我想要的收益孩子表現出從U_PD_description領域的所有結果,其中U_PD_type =「收益「,即
- Component ....Parent
Earnings ....child
Housing Allowance
Mobile Phone Allowance
Mileage Allowance
Deductions ....child
並且同樣用於扣除。我有以下代碼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();
}
誰能告訴我如何填充說,在爲TreeView1盈利樹的一個例子嗎?
非常感謝!住房補貼,手機記錄不會是靜態的。所以我想我必須從結果中創建一個列表 –
是的,你已經有了它們只是爲每個循環循環並添加到teeview節點。我只是舉了一個例子。 – Reniuz
好吧,知道了Renuiz,再次感謝 –