How to set columnNames for dataGridView associated with List <T>?

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

DataGridView.Datasource = EquipList;

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

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

Well, maybe I did not explain myself correctly ... I hope that there is an attribute that can be applied, for example ....

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

if not, I'll just stick to the old tired ways

Later that morning ....

I understood!

 using System.ComponentModel;

[DisplayName("the nice name")]
 public int EquipID {get;set;}
+5
source share
2 answers

It works.

using System.ComponentModel;

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

DataGridView.Datasource = EquipList;

: , .

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

DataGridViewTextBoxColumn dt = new DataGridViewTextBoxColumn();
dt.DataPropertyName = "EquipName"; //Property to bind.
dt.HeaderText = "Name";
dataGridView1.Columns.Add(dt);

Designer.

+1

All Articles