简体   繁体   中英

How to make a datagridview display the contents of an array?

I have a 1d array listOfValues . It contains double values. I want to display its values into a datagridview named as dataGridVal .

I did dataGridVal.Source = listOfValues but its not working.

Did I miss something???

DataGridView binds its columns to properties of items in data source. Thus double type do not have any properties, you can't bind directly to that type.

HINT: you can project double values into anonymous objects:

dataGridVal.DataSource = listOfValues.Select(d => new { Value = d }).ToArray();

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