我有一個函數將LINQ結果綁定到窗體上的控件。下面的代碼工作,但我不能克服我應該爲複製/粘貼方面打耳光的感覺。有人可以幫我解決這個問題嗎?將控件綁定到LINQ的重構方法
謝謝!
private void BindDataToForm()
{
// Bind data to form
CaseNotesDataContext db = new CaseNotesDataContext();
Table<CN_MaintItem> caseNotesItems = db.GetTable<CN_MaintItem>();
// For each object
var contactType = from cType in caseNotesItems
where cType.CategoryID == 2
select cType.ItemDescription;
chkContactType.DataSource = contactType;
var contactLocation = from cLocation in caseNotesItems
where cLocation.CategoryID == 3
select cLocation.ItemDescription;
lkuContactLocation.Properties.DataSource = contactLocation;
var contactMethod = from cMethod in caseNotesItems
where cMethod.CategoryID == 4
select cMethod.ItemDescription;
lkuContactMethod.Properties.DataSource = contactMethod;
var contactWith = from cWith in caseNotesItems
where cWith.CategoryID == 5
select cWith.ItemDescription;
chkContactWith.DataSource = contactWith;
var domains = from d in caseNotesItems
where d.CategoryID == 6
select d.ItemDescription;
chkDomains.DataSource = domains;
}
你根本沒有通過這個表 – 2009-04-14 21:14:41
哦,noes,friggen世界的盡頭,填補那個空白Nick ... – leppie 2009-04-14 21:17:03