473,671 Members | 2,261 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I bind a Windows Forms Datagrid to a collection?

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
Nov 21 '05 #1
11 2491
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******@WEDEL IVERcc3.com> wrote in message
news:Xn******** *************** ***********@207 .46.248.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
Nov 21 '05 #2
"Ken Tucker [MVP]" <vb***@bellsout h.net> wrote:
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******@WEDEL IVERcc3.com> wrote in message
news:Xn******** *************** ***********@207 .46.248.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

Nov 21 '05 #3
Maybe you also need to set the data member to the data table?

"Michael Kellogg" <mk******@WEDEL IVERcc3.com> wrote in message
news:Xn******** *************** ***********@207 .46.248.16...
"Ken Tucker [MVP]" <vb***@bellsout h.net> wrote:
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******@WEDEL IVERcc3.com> wrote in message
news:Xn******** *************** ***********@207 .46.248.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

Nov 21 '05 #4
"bill" <be****@datamti .com> wrote:
Maybe you also need to set the data member to the data table?

Could you give me an example of this?

--
Michael
Nov 21 '05 #5
Sorry, I was thinking of datasets not collections.

Does your custom object class have a Get property (such as 'Name') to be
displayed in the datagrid?
"Michael Kellogg" <mk******@WEDEL IVERcc3.com> wrote in message
news:Xn******** *************** ***********@207 .46.248.16...
"bill" <be****@datamti .com> wrote:
Maybe you also need to set the data member to the data table?

Could you give me an example of this?

--
Michael

Nov 21 '05 #6
"bill" <be****@datamti .com> wrote:
Sorry, I was thinking of datasets not collections.

Does your custom object class have a Get property (such as 'Name') to be
displayed in the datagrid?


No, I didn't get that complicated with it. It's little more than about 20
"fields". Do I need to set a Default Get property or something?

--
Michael Kellogg
Nov 21 '05 #7
That is how I did it. If your object has Get properties, the datagrid will
display them. There should be one property for each field to be displayed
in the datagrid.

For example, if the widget class has a public WidgetName property which
returns the widget name, there will be a WidgetName column in the datagrid.
It will display the name property for each widget entered into the Widget
collection which is the data source for the datagrid. If there is no Get
property function, the datagrid has nothing to display.

"Michael Kellogg" <mk******@WEDEL IVERcc3.com> wrote in message
news:Xn******** *************** ***********@207 .46.248.16...
"bill" <be****@datamti .com> wrote:
Sorry, I was thinking of datasets not collections.

Does your custom object class have a Get property (such as 'Name') to be
displayed in the datagrid?


No, I didn't get that complicated with it. It's little more than about 20
"fields". Do I need to set a Default Get property or something?

--
Michael Kellogg

Nov 21 '05 #8
"bill" <be****@datamti .com> wrote:
That is how I did it. If your object has Get properties, the datagrid
will display them. There should be one property for each field to be
displayed in the datagrid.

For example, if the widget class has a public WidgetName property
which returns the widget name, there will be a WidgetName column in
the datagrid. It will display the name property for each widget
entered into the Widget collection which is the data source for the
datagrid. If there is no Get property function, the datagrid has
nothing to display.


Well I figured that since all my member variables were Public, that would
take care of that. I will experiment with a GET and see what happens.

Thanks!

--
Michael Kellogg
Nov 21 '05 #9
"bill" <be****@datamti .com> wrote:
That is how I did it. If your object has Get properties, the datagrid
will display them. There should be one property for each field to be
displayed in the datagrid.

For example, if the widget class has a public WidgetName property
which returns the widget name, there will be a WidgetName column in
the datagrid. It will display the name property for each widget
entered into the Widget collection which is the data source for the
datagrid. If there is no Get property function, the datagrid has
nothing to display.


Well I figured that since all my member variables were Public, that would
take care of that. I will experiment with a GET and see what happens.

Thanks!

--
Michael Kellogg
Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1710
by: yaniv abo | last post by:
Hello. How can I bind a list of objects to a DataGird? I have a custom collection of Customer class
3
1467
by: philip.mckee | last post by:
Hi all I am looking to return the width of a given column in a Windows.Forms.DataGrid at runtime. This would seem to be a much needed straight forward property request, but I can't find a simple way of getting it. I believe the DataGridColumnStyle class should be able to return this width, but how do you get the DataGridColumnStyle instance for a given column? I am sure that there is a collection somewhere but cant find. My datagrid is...
2
2091
by: Pete Nelson | last post by:
Does anyone know of a way to bind a string collection to a datagrid? Basically, I have an object, CreditPlans, and a string collection, ModelNumbers. I'd like to bind the ModelNumbers collection to the datagrid, but because there isn't a custom object with properties, just a string object, I'm not sure how to reference it in the datagrid. FYI, I can enumerate through the collection... foreach(string modelNum in...
4
4085
by: Greg Linwood | last post by:
I am wondering what the best approach to binding XML data to an asp:Table from the Page_Load event in a code behind module? I'm using VB.Net and initially approached this by adding a table to the web page from the VS2003 ASP page designer, extracting an XML document from SQL Server during Page_Load, then adding asp:TableRows & asp:TableCells one at a time / loading the corresponding xml values a cell at a time. Is there a better (less...
2
2201
by: A Traveler | last post by:
Hi, I have a custom collection class i wrote, LineItemsCollection, which is a strongly typed collection of objects of my LineItem class. The LineItem class is a simple class with just a couple properties, ProdID, Description, Quantity and UPC. 3 strings and a long. The LineItemsCollection class inherits from System.Collections.Specialized.NameObjectCollectionBase. It also implements both IEnumerable and IList.
1
2935
by: Doug D via .NET 247 | last post by:
I really really need some insight on this problem I am trying to bind a strongly typed collection object to a datagrid. I already Inherited CollectionBase, but .NET says that it cannot find my property name, when I try to bind it to the grid.. now, here is where it gets tricky. Do I NEED to Implement IBindingList, on my collection object, since my object that I am adding to the collection inherits from a another class? here is my...
6
4356
by: Bob The Builder | last post by:
I have a custom-built datagrid for windows forms. I overrode the scrollbars in it because I wanted to draw my own (basically, they're skinned). As a result, I handle all scroll events and calls. I also have a row-selector column as the first column, and that needs to stay visible. Think Excel. However, if a user clicks a cell that is all the way to the right and goes off the grid a bit, then the entire grid shifts, including my...
3
3283
by: serge calderara | last post by:
Dear all, Does anyone know how to bind a System.Collection.ArraysList object to a Dataset ? Thanks for your reply Regards Serge
1
1334
by: Řyvind Isaksen | last post by:
I try to make my own ArticleAttribute object and ArticleAttributeCollection, and add data to this Collection. It almost works, but the problem is that each time I add an ArticleAttribute to my Collection, it seems like it overwrites the other ArticleAttributes. When bind the ArticleAttributeCollection to a datagrid, all articleattributes are the same. This is what my datagrid dispays: ID Content
0
8393
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8917
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8670
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7437
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6229
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2812
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1809
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.