开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜