I have a WinForms form with a DataGridView on. The DataGridView are populated from a LINQ to SQL query as below. When I run the code the gridview seems to show the column value and not the actual value.
The DataGridView does not have a design time source, and the columns have a DataPropertyName that is equal to the column in the database.
What am I missing that it doesn't display the actual value?
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();
the problem is in the select
select new { DateSent, DateReceived, ReceivedFrom})
should be
select new { DateSent=r.DateSent, DateReceived=r.DateReceived, ReceivedFrom=r.ReceivedFrom})
you are selecting the columns and not the values
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.