简体   繁体   English

数据网格中的自定义列标题从ArrayList查看C#

[英]Custom Column Headers in Data Grid View C# from ArrayList

I am creating a dataGridView which gets its values from an arrayList. 我正在创建一个dataGridView,它从arrayList获取其值。 To retrieve the values, I have: 要检索值,我有:

   public DataSet(String totalCM, String totPM, String hkCM, String hkPM, String sherCM, String sherPM, String hinsCM, String hinsPM, String kassCM, String kassPM, String belleCM, String bellePM)
   {
       _totalCM = totalCM;
       _totalPM = totPM;
       _hiddenKnollsCM = hkCM;
       _hiddenKnollsPM = hkPM;
       _sherCM = sherCM;
       _sherPM = sherPM;
       _hinsdaleCM = hinsCM;
       _hinsdalePM = hinsPM;
       _kassonCM = kassCM;
       _kassonPM = kassPM;
       _belleCM = belleCM;
       _bellePM = bellePM;

   }
   public String TotalCurrentMonth
   {
       get { return _totalCM; }
   }
   public String TotalPreviousMonth
   {
       get { return _totalPM; }
   }
   public String HiddenKnollsCurrentMonth
   {
       get { return _hiddenKnollsCM; }
   }
   public String HiddenKnollsPreviousMonth
   {
       get { return _hiddenKnollsPM; }
   }
   public String SherwoodCurrentMonth
   {
       get { return _sherCM; }
   }
   public String SherwoodPreviousMonth
   {
       get { return _sherPM; }
   }
   public String HinsdaleCurrentMonth
   {
       get { return _hinsdaleCM; }
   }
   public String HinsdalePreviousMonth
   {
       get { return _hinsdalePM; }
   }
   public String KassonCurrentMonth
   {
       get { return _kassonCM; }
   }
   public String KassonPreviousMonth
   {
       get { return _kassonPM; }
   }
   public String BelleIsleCurrentMonth
   {
       get { return _belleCM; ; }
   }
   public String BelleIslePreviousMonth
   {
       get { return _bellePM; }
   }
} 

How do I go about creating custom column headers for this, as they need to have a space? 如何为此创建自定义列标题,因为它们需要有空格? Probably a really dumb question, but could not find much information about this specific issue. 可能是一个非常愚蠢的问题,但无法找到有关此特定问题的大量信息。 I know that you can modify the properties in the collection of column names, but it just seems to create new column header names based off of the accessor methods in the code. 我知道你可以修改列名集合中的属性,但它似乎只是根据代码中的访问器方法创建新的列标题名称。 Thanks in advance. 提前致谢。

Well, if you're using .NET 2+ you can use the DisplayNameAttribute Class . 好吧,如果您使用的是.NET 2+,则可以使用DisplayNameAttribute类

Use in on your properties to specify the string used in the column headers of your DGV; 在您的属性中使用以指定DGV列标题中使用的字符串; otherwise the property name will be used (as you see). 否则将使用属性名称(如您所见)。

And if you're using .NET 2+ you shouldn't be using an ArrayList, use a List<T> instread. 如果您使用的是.NET 2+,则不应使用ArrayList,请使用List<T> instread。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM