zoukankan      html  css  js  c++  java
  • DataGridView 绑定List时 属性不显示的解决方法

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

  • 相关阅读:
    MSSQL Join的使用
    MSSQL2008 常用sql语句
    Process使用
    c# 多线程 调用带参数函数
    C# 多线程参数传递
    C# 单例模式代码
    C#调用存储过程
    页面布局
    构建:vue项目配置后端接口服务信息
    浏览器工作原理(二):浏览器渲染过程概述
  • 原文地址:https://www.cnblogs.com/oftenlin/p/2616678.html
Copyright © 2011-2022 走看看