日期:2014-05-17 浏览次数:20848 次
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication4
{
public partial class Form2 : Form
{
class Item
{
public int ID { get; set; }
public string Name { get; set; }
public double Value { get; set; }
public DateTime UpdateDateTime { get; set; }
}
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
var list = new List<Item>();
for (int i = 0; i < 20; i++)
{
list.Add(new Item()
{
ID = i,
Name = "Name of " + i.ToString(),
Value = i,
UpdateDateTime = DateTime.Now
});
}
dataGridView1.DataSource = list;
List<Item> nlist = (List<Item>)dataGridView1.DataSource;
var resultTable = ConvertToDataTable<List<Item>>(nlist);
var resultList = ConvertToList<List<Item>>(resultTable);