简体   繁体   中英

DataGridView shows type and not the value

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM