如何将Windows窗体数据网格绑定到集合? [英] How can I bind a Windows Forms Datagrid to a collection?

查看:82
本文介绍了如何将Windows窗体数据网格绑定到集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组自定义对象,我在Windows

Forms Datagrid中显示。为了显示它,我采取了集合并动态构建了一个DataTable

对象,然后将网格的DataSource设置为DataTable。

代码很长,网格显然不可编辑。我已经阅读了

它可以直接连接我的收藏,并且可以编辑,

。任何人都可以指点我的资源,可以带我走过这个吗?


TIA


-

迈克尔

I have a collection of custom objects that I am displaying in a Windows
Forms Datagrid. To display it, I take the collection and build a DataTable
object on the fly, then set the grid''s DataSource to the DataTable. The
code for this is lengthy and the grid is obviously not editable. I''ve read
it''s possible to connect my collection directly, and have it be editable,
too. Can anyone point me to a resource that can walk me through this?

TIA

--
Michael

推荐答案




如果将datagrids数据源设置为集合中的任何属性
您的自定义类中的
将显示在datagrid中。如果你要将一个

tablestyle添加到datagrid use collection作为映射名称。


Ken

----- ---------------

" Michael Kellogg" < MK ****** @ WEDELIVERcc3.com>在消息中写道

新闻:Xn ********************************** @ 207.46 .2 48.16 ...

我有一组自定义对象,我在Windows

Forms Datagrid中显示。为了显示它,我采取了集合并动态构建了一个DataTable

对象,然后将网格的DataSource设置为DataTable。

代码很长,网格显然不可编辑。我已经阅读了

它可以直接连接我的收藏,并且可以编辑,

。任何人都可以指点我的资源,可以带我走过这个吗?


TIA


-

迈克尔
Hi,

If you set the datagrids datasource to the collection any properties
in your custom class will be displayed in the datagrid. If you are adding a
tablestyle to the datagrid use collection as the mapping name.

Ken
--------------------
"Michael Kellogg" <mk******@WEDELIVERcc3.com> wrote in message
news:Xn**********************************@207.46.2 48.16...
I have a collection of custom objects that I am displaying in a Windows
Forms Datagrid. To display it, I take the collection and build a DataTable
object on the fly, then set the grid''s DataSource to the DataTable. The
code for this is lengthy and the grid is obviously not editable. I''ve read
it''s possible to connect my collection directly, and have it be editable,
too. Can anyone point me to a resource that can walk me through this?

TIA

--
Michael


" Ken Tucker [MVP]" < VB *** @ bellsouth.net>写道:
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote:


如果您将datagrids数据源设置为集合,将显示您的自定义类中的任何
属性
在datagrid中。如果您要将tablestyle添加到datagrid use集合作为映射
名称。


我曾尝试过几次将datagrid的数据源设置为我的

集合,但我得到的只是一个空数据网格。我知道这个系列充满了数据;我错过了什么?


mk

" Michael Kellogg" < MK ****** @ WEDELIVERcc3.com>在消息中写道
新闻:Xn ********************************** @ 207.46.2 48.16。 ..
我有一组自定义对象,我在Windows窗体数据网格中显示。为了显示它,我采用了该集合并动态构建了一个DataTable对象,然后将网格的DataSource设置为DataTable。这个代码很冗长,网格显然不可编辑。我已经读过它可以直接连接我的收藏品了,并且可以编辑它。谁能指点我一个可以引导我完成这个的资源?

TIA
Hi,

If you set the datagrids datasource to the collection any
properties
in your custom class will be displayed in the datagrid. If you are
adding a tablestyle to the datagrid use collection as the mapping
name.
I''ve tried a few times to just set the datagrid''s datasource to my
collection but all I get is a blank datagrid. I know the collection is
full of data; what am I missing?

mk
"Michael Kellogg" <mk******@WEDELIVERcc3.com> wrote in message
news:Xn**********************************@207.46.2 48.16...
I have a collection of custom objects that I am displaying in a
Windows Forms Datagrid. To display it, I take the collection and
build a DataTable object on the fly, then set the grid''s DataSource to
the DataTable. The code for this is lengthy and the grid is obviously
not editable. I''ve read it''s possible to connect my collection
directly, and have it be editable, too. Can anyone point me to a
resource that can walk me through this?

TIA



也许你也需要将数据成员设置为数据表?


" Michael Kellogg" < MK ****** @ WEDELIVERcc3.com>在消息中写道

新闻:Xn ********************************** @ 207.46 .2 48.16 ...
Maybe you also need to set the data member to the data table?

"Michael Kellogg" <mk******@WEDELIVERcc3.com> wrote in message
news:Xn**********************************@207.46.2 48.16...
" Ken Tucker [MVP]" < VB *** @ bellsouth.net>写道:
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote:


如果您将datagrids数据源设置为集合,将显示您的自定义类中的任何
属性
在datagrid中。如果你是将datastyle添加到datagrid使用集合作为映射
名称。
Hi,

If you set the datagrids datasource to the collection any
properties
in your custom class will be displayed in the datagrid. If you are
adding a tablestyle to the datagrid use collection as the mapping
name.



我已经尝试了几次来设置datagrid'我的
集合的数据源,但我得到的只是一个空白的数据网格。我知道这个系列充满了数据;我错过了什么?

mk



I''ve tried a few times to just set the datagrid''s datasource to my
collection but all I get is a blank datagrid. I know the collection is
full of data; what am I missing?

mk

" Michael Kellogg" < MK ****** @ WEDELIVERcc3.com>在消息中写道
新闻:Xn ********************************** @ 207.46.2 48.16。 ..
我有一组自定义对象,我在Windows窗体数据网格中显示。为了显示它,我采用了该集合并动态构建了一个DataTable对象,然后将网格的DataSource设置为DataTable。这个代码很冗长,网格显然不可编辑。我已经读过它可以直接连接我的收藏品了,并且可以编辑它。谁能指点我一个可以引导我完成这个的资源?

TIA
"Michael Kellogg" <mk******@WEDELIVERcc3.com> wrote in message
news:Xn**********************************@207.46.2 48.16...
I have a collection of custom objects that I am displaying in a
Windows Forms Datagrid. To display it, I take the collection and
build a DataTable object on the fly, then set the grid''s DataSource to
the DataTable. The code for this is lengthy and the grid is obviously
not editable. I''ve read it''s possible to connect my collection
directly, and have it be editable, too. Can anyone point me to a
resource that can walk me through this?

TIA



这篇关于如何将Windows窗体数据网格绑定到集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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