简体   繁体   中英

Easiest way to display array of values in table in windows form C#

I have an array(rows) of arrays which contains 4 elements which I would like to display in a grid or table in a Windows form in C#.

What is the most straightforward way to accomplish this? Is there a way to bind a data grid to an array (or object perhaps)?

What is your recommendation?

You're looking for the DataGridView control .

Instead of an array of arrays, you should make a class with four properties, then make a BindingList<T> of that class.

as SLaks said, that is a more structured way of doing it, here is a way that uses Linq + Anonymous Types to do something similar on the fly:

int[] numbers = new int[] { 1, 2, 3, 4, 5 };
var evens = from n in numbers select new { Digit = n, Even = (n % 2 == 0) } ;
dataGridView1.DataSource = evens.ToList();

Also if you are after nice ways of displaying then have a look at WPF beats Windows Form hands down.

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