c# dataGridView绑定string数组数据源

来源:互联网 发布:gta5低配优化 编辑:程序博客网 时间:2024/05/17 23:33

//我们需要包装一下数组,方法如下:

//不想要列标题,可以设置去掉列标题

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form10 : Form
    {
        public Form10()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
         
            Item[] items = new Item[] { new Item("one"), new Item("two"), new Item("three") };

            this.dataGridView1.DataSource = items;
        }
    }
    class Item
    {
        private string _text;
        public string Text
        {
            get { return _text; }
        }
        public Item(string text)
        {
            this._text = text;
        }
    }
}


原创粉丝点击