1
我正在從Windows窗體移動到WPF,但現在我有一個問題。wpf:如何在網格視圖中顯示數據集?
我從數據庫(SQL Server)的信息,並存儲在數據集中,我想表明,在一個DataGrid(DG)
DataSet ds = new DataSet();
SqlConnection sc = new SqlConnection("mysqlconnection");
SqlDataAdapter sd = new SqlDataAdapter();
sc.Open();
sd.SelectCommand = new SqlCommand("SELECT * FROM table_1", sc);
sd.Fill(ds);
dg.DataContext = ds.Tables[0].DefaultView;//here is the problem
sc.Close();
在Windows窗體是dg.DataSrouce
,但我無法找到在wpf中,有什麼幫助?
感謝您的回答,我可以看到有4行是真的,但我沒有看到這4行內的任何列或數據! – trrrrrrm 2011-03-04 07:42:08
@ From.ME.to.YOU:更新了我的答案,嘗試在'DataGrid'定義中設置'AutoGenerateColumns ='True'' – 2011-03-04 07:43:55
非常感謝,像魔術一樣工作! – trrrrrrm 2011-03-04 07:48:14