开发者

Setting DataSource of a DataGridView control. Am I doing this right? C#

Consider my code:

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

namespace ClassTest
{
    public partial class Form1 : Form
    {
        List<Employee> employeeList;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            employeeList = new List<Employee>();
            employeeList.Add(new Employee("000001", "DELA CRUZ, JUAN T."));
            employeeList.Add(new Employee("000002", "GOMEZ, MAR B."));
            employeeList.Add(new Employee("000003", "RIVERA, ERWIN J."));

            dataGridView1.DataSource = employeeList;
        }
    }

    public class Employee
    {
        public Employee(string employeeNo, string name)
        {
            this.employeeNo = employeeNo;
            this.name = name;
        }

       开发者_Python百科 public string employeeNo;
        public string name;
    }
}

I got no output for this...

Where did I go wrong?


You need to have public properties for the columns to autogenerate.

Try

    public string employeeNo { get; set; }
    public string name { get; set; }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜