2014-12-19 78 views
0

我有一個WinForms格式的DataGridView。 DataGridView從LINQ填充到SQL查詢如下。當我運行代碼時,gridview似乎顯示列值而不是實際值。DataGridView顯示類型而不是值

DataGridView沒有設計時間源,並且這些列的DataPropertyName等於數據庫中的列。

我錯過了什麼,它不顯示實際值?

var q = (from r in db.MessagesReceived 
     orderby r.ID descending 
     select new { DateSent, DateReceived, ReceivedFrom}).Take(TopNumber); 


//dgv.AutoGenerateColumns = false; 
dgv.DataSource = q; 
dgv.Refresh(); 

enter image description here

+0

什麼是'DateSent ','DateReceived'和'ReceivedFrom'? – 2014-12-19 09:32:00

回答

3

問題是在選擇

select new { DateSent, DateReceived, ReceivedFrom}) 

應該

select new { DateSent=r.DateSent, DateReceived=r.DateReceived, ReceivedFrom=r.ReceivedFrom}) 

您選擇的列,而不是值