简体   繁体   English

绑定winforms datagridview行标题

[英]Bind winforms datagridview rowheader

In C# Winforms DataGridView I am binding a List of class using the datagriview's datasource property. 在C#Winforms DataGridView我使用datagriview的datasource属性绑定了一个类列表。 Is there a way to bind one of the class property to the datagriview's rowheader ? 有没有一种方法可以将class属性之一绑定到datagriview的行rowheader

I didn't want to iterate all the rows and add row header values one by one because I will have thousands of records so I wanted the rowheader to get the values from the binded class when I set the datasource. 我不想iterate所有行并一一添加行标题值,因为我将拥有成千上万的记录,因此我希望行标题在设置数据源时从绑定类中获取值。

For example I have this class and I want the rowheaders to show the Customer ID. 例如,我有此类,并且我希望行标题显示客户ID。

private class Customer
{
   public string CustomerID { get; set; }
   public string CustomerFirstName { get; set; }
}

I'm afraid you have to implement datagridview's OnPaint -Method, where you paint the customer id in a loop. 恐怕您必须实现datagridview的OnPaint -Method,在该方法中您可以循环绘制客户ID。 Once, I wanted to numerate my entries and I didn't find any other solution. 一次,我想编号我的条目,但没有找到其他解决方案。

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

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