2010-11-08 68 views
0

考慮我的代碼:設置DataGridView控件的DataSource。我做對了嗎? C#

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; 
     } 

     public string employeeNo; 
     public string name; 
    } 
} 

我沒有輸出這...
我有什麼錯?

+0

難道你有一個錯誤或您的網格是空 – nemke 2010-11-08 00:17:18

+0

爵士,只是沒有輸出.... – yonan2236 2010-11-08 00:21:27

回答

1

您需要具有自動生成列的公共屬性。

嘗試

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

不工作....肯定是正在執行沒有錯誤 – yonan2236 2010-11-08 00:20:48

+0

你負荷的方法?我用我的建議更改試過了你的代碼,它可以在我的電腦上同時運行.Net 3.5和4.0 – grantnz 2010-11-08 00:32:48

+0

這必須工作。我現在在我的電腦上進行測試,並且像魅力一樣工作! – nemke 2010-11-08 00:33:16