开发者

How do I use TypeDescription to create ClassA with child ClassB's attributes?

开发者 https://www.devze.com 2023-03-22 19:36 出处:网络
I\'m working on a C# project in which i would like a datagridview to show certain columns. I can show columns of attributes of Class A, which is no problem.

I'm working on a C# project in which i would like a datagridview to show certain columns. I can show columns of attributes of Class A, which is no problem.

        DataGridViewTextBoxColumn idColumn = new DataGridViewTextBoxColumn();
        idColumn.DataPropertyName = "Id";
        idColumn.HeaderText = "Id";

But I have a problem at creating a column of Class B this way.

        DataGridViewTextBoxColumn idColumn = new DataGridViewTextBoxCol开发者_开发技巧umn();
        idColumn.DataPropertyName = "ClassB.Name";
        idColumn.HeaderText = "Name";

I have been searching the internet for a solution and I know now that you can't add a attribute from Class B this way. Though i think there is a solution by using TypeDescriptor somehow. The problem is, I do not understand how this is suppose to work.

So I'm looking for someone who can explain to me in detail how to use the class "TypeDescriptor" by using the method "AddProvider" so that i can create a column, in the datagridview, from an attribute from Class B.

PS: I'm not allowed to edit the existing classes, though i can use Extension methods.

0

精彩评论

暂无评论...
验证码 换一张
取 消