Windows窗体:在DataGridView显示子对象的价值 [英] Windows Form: showing child object value in the DataGridView

查看:112
本文介绍了Windows窗体:在DataGridView显示子对象的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有有子产品对象的productVariant对象。我想在DataGridView显示值,任何人都可以让我知道如何做到这一点?

I have a productVariant object which has child product object. I want to show the value in the DataGridView, can anyone let me know how to do this?

下面是对象的结构。

我试图绑定ProductVariant.Product.Name到DataProptertyName在DataGridView,但是,它没有不显示任何值。

I tried to bind "ProductVariant.Product.Name" to the DataProptertyName in the DataGridView, however, it did not not showing any value.

任何人都可以在这方面帮助?非常感谢。

Can anyone help with this? Many thanks.

推荐答案

DataGridView中的控件不能绑定子自动对象。

DataGridView-controls can not bind child objects automatically.

如果您正在使用的Win-形式的工作,我的建议是创建两个对话框窗口。

If you are working with Win-forms, my suggestion would be to create two Dialog windows.

一个是父对象(带DGV)和另一为儿童的对象(具有DGV)。

One is for parent-objects(with a DGV) and another is for child-objects(with a DGV).

当用户打开父窗口,父对象会被加载逐行在DGV

When the user opens the parent window, parent objects would be loaded row-wise in the DGV.

然后,如果用户双击父窗口上的行,子窗口将被示出和该父的子对象将在DGV对孩子进行填充窗口。

Then if the user double-clicks a row on the parent-window, the child-window would be shown up and the child objects of that parent would be populated on the DGV on the child window.

在这种方式你可以保持干净的东西,不管父子关系有多深。此外,添加,编辑,删除等操作会更清洁

In this way you can keep things clean no matter how deep the parent-child relationships go. Moreover, add, edit, delete, etc. operations would be much cleaner.

您也可以使用一些第三方控件一样,的 HierarchicalDataGridView

You can also use some third-party controls like, HierarchicalDataGridView.

这篇关于Windows窗体:在DataGridView显示子对象的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆