您好我是C#和WPF的新手,我想要顯示一個用戶對象列表(PartnerID和PartnerName)和一個詢問是否刪除數據網格中的合作伙伴的複選框。我寫了下面的代碼,但僅顯示列標題,並且不顯示值。我認爲它與綁定的問題,但我無法追查它。你能plz幫助我..顯示數據網格中的對象列表
private void Window_Loaded(object sender, RoutedEventArgs e)
{
List<Partners> partners = new List<Partners>();
DataAccess DA = new DataAccess();
partners = DA.GetAllPartners();
this.dataGrid1.DataContext = partners;
this.dataGrid1.Columns.Add(new DataGridTextColumn { Header = "Id", Binding new Binding("PartnerId") });
this.dataGrid1.Columns.Add(new DataGridTextColumn { Header = "Partner Name", Binding = new Binding("PartnerName") });
this.dataGrid1.Columns.Add(new DataGridCheckBoxColumn
{
Header = "Delete?",
Binding = new Binding(" ")
});
}
在此先感謝
爲什麼不在XAML中做這件事?後面的代碼是複雜的,更容易出錯在像這些 – 2011-12-29 06:35:38