如何设置COLUMNNAMES绑定到一个列表与下一个DataGridView; T&GT ;? [英] How do I set columnNames for a dataGridView bound to a List<T>?

查看:130
本文介绍了如何设置COLUMNNAMES绑定到一个列表与下一个DataGridView; T&GT ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如下图所示,我创建equip.I的List想有列名更具描述性的 - 是没有办法,我可以在equip.properties使用属性


$ B $? b

  DataGridView.Datasource = EquipList; 

名单,LT;装备> EquipList =新的List<&配备GT;();

公共类装备
{
公众诠释EquipID {获取;设置;}
公共字符串EquipName {获取;集;}
}

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

  [阿里(名字,我想看看在GridView)] 
酒店的公共INT EquipID {获取;设置;}

如果没有我就坚持使用旧的累方法



后来同一天上午....



我知道了!

 使用System.ComponentModel; 

[显示名称(下称好听的名字)]
公众诠释EquipID {获取;集;}


解决方案

该工程..

 使用系统.ComponentModel; 

名单,LT;装备> EquipList =新的List<&配备GT;();

DataGridView.Datasource = EquipList;



如下:类中的前两个属性会显示与
与他们的新名字,第三个属性将不会显示为每
可浏览属性。

 公共类装备
{
〔显示名称(设备ID)]
公众诠释EquipID {获取;设置;}

[显示名称(设备名称)]
公共字符串EquipName {获取;设置;}

[可浏览(假)]
公众诠释的recordId {搞定;私人集;}
}


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....

I got it!

 using System.ComponentModel;

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

解决方案

This works..

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

这篇关于如何设置COLUMNNAMES绑定到一个列表与下一个DataGridView; T&GT ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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