如何为绑定到 List<T> 的 dataGridView 设置 columnNames? [英] How do I set columnNames for a dataGridView bound to a List&lt;T&gt;?

查看:14
本文介绍了如何为绑定到 List<T> 的 dataGridView 设置 columnNames?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如下所示,我创建了一个装备列表.我想让列名称更具描述性 - 是否有我可以在装备.properties 中使用的属性?

As shown below I have created a List of equip.I would like to have the column names more descriptive - is there an attribute that I can use in the equip.properties?

DataGridView.Datasource = EquipList;

List<equip> EquipList = new List<equip>();

public class equip
{
 public int EquipID {get;set;}
 public string EquipName {get;set;}
}

好吧,也许我没有正确解释自己......我希望有一个可以应用的属性......

Okay, maybe I didn't explain myself properly...I am hoping that that there is an attribute that could be applied like....

[Alis("name I would like to see in the gridview")]
public int EquipID {get;set;}

如果不是,我就坚持老旧的方式

if not I'll just stick with the old tired ways

在同一天早上晚些时候......

Later on that same morning....

我明白了!

 using System.ComponentModel;

[DisplayName("the nice name")]
 public int EquipID {get;set;}

推荐答案

这有效..

using System.ComponentModel;

List<equip> EquipList = new List<equip>();

DataGridView.Datasource = EquipList;

下面:类中的前两个属性将显示为使用他们的新名称,第三个属性将不会按照可浏览属性.

below:the first two properties in the class will be displayed with with their new names, the third property will not display as per the Browsable attribute.

public class equip
  {
   [DisplayName("Equipment ID")]
   public int EquipID {get;set;}

   [DisplayName("Equipment Name")]
   public string EquipName {get;set;}

   [Browsable(false)]
   public int recordId {get; private set;}
  }

这篇关于如何为绑定到 List<T> 的 dataGridView 设置 columnNames?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆