DataGridViewTextBoxColumn col1 = new DataGridViewTextBoxColumn();            

col1.HeaderText = "姓名";            

col1.DataPropertyName = "Name";            

col1.Name = "Name";                        

col1.Width = 100;            

DataGridViewTextBoxColumn col2 = new DataGridViewTextBoxColumn();            

col2.HeaderText = "性别";            

col2.DataPropertyName = "Sex";            

col2.Name = "Sex";            

col2.Width = 80;

this.dataGridView1.Columns.Add(col1);            

this.dataGridView1.Columns.Add(col2);

 

IList<User> list = new List<User>();            

list.Add(new User("wtq", "男"));            

list.Add(new User("wtm", "男"));            

list.Add(new User("wts", "男"));

this.dataGridView1.DataSource = list;

// User 类

public class User
{
        public  User(string userName,string sex)
        {
            this.Name = userName;
            this.Sex = sex;
        }

    /*注意必须要写成如此形式才能显示,写成public string Name; DataGridView里面不显示*/
        public string Name  {get;set;}
        public string Sex   {get;set;}
}

相关文章:

  • 2021-10-04
  • 2022-12-23
  • 2022-01-03
  • 2021-06-07
  • 2021-08-29
  • 2022-12-23
  • 2018-06-21
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-08
  • 2022-02-08
  • 2022-01-05
  • 2021-05-21
  • 2022-01-26
相关资源
相似解决方案