473,724 Members | 2,245 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BindingSource for a class - need a light bulb moment

TN
I just don't get the BindingSource class when it is bound to a class.
Consider this code snip:

.....
Private bSource As New BindingSource()
Private dgv As New DataGridView()

Public Sub New()
InitializeCompo nent()

' Bind the BindingSource to the DemoCustomer type !!!!!!!!!!!!!
bSource.DataSou rce = GetType(DemoCus tomer)

' Set up the DataGridView control.
dgv.Dock = DockStyle.Fill
Me.Controls.Add (dgv)

' Bind the DataGridView control to the BindingSource.
dgv.DataSource = bSource
End Sub
.....

Assuming "DemoCustom er" is a simple class with a few properties, how is
it storing the data. Normally I bind a datasource to an instance of a
datatable or something. Where is the list of DemoCustomer's instances
stored? I am missing something obvious here, yes? Thanks.
Jan 13 '06 #1
1 4537
Hi,

"TN" <ti*******@phre aker.net> wrote in message
news:O9******** ******@TK2MSFTN GP12.phx.gbl...
I just don't get the BindingSource class when it is bound to a class.
Consider this code snip:

....
Private bSource As New BindingSource()
Private dgv As New DataGridView()

Public Sub New()
InitializeCompo nent()

' Bind the BindingSource to the DemoCustomer type !!!!!!!!!!!!!
bSource.DataSou rce = GetType(DemoCus tomer)

' Set up the DataGridView control.
dgv.Dock = DockStyle.Fill
Me.Controls.Add (dgv)

' Bind the DataGridView control to the BindingSource.
dgv.DataSource = bSource
End Sub
....

Assuming "DemoCustom er" is a simple class with a few properties, how is it
storing the data. Normally I bind a datasource to an instance of a
datatable or something. Where is the list of DemoCustomer's instances
stored? I am missing something obvious here, yes? Thanks.


When you assign a Type of a class (that doesn't implement ITypedList or
IListSource) to the DataSource of a BindingSource, then it will create a
System.Componen tModel.BindingL ist( Of T ) for the items, eg. :
BindingList( Of DemoCustomer ) .

You can access this BindingList from BindingSource's List property, eg:

Dim list As BindingList( Of DemoCustomer ) = DirectCast( _
bSource.List, BindingList( Of DemoCustomer ) )

AFAIK, you should not assign a Type to the DataSource of a BindingSource
from Code. It's mainly used when you drag a custom object from the Data
Sources Window onto the Form. When you do that there won't be an instance
of the custom object placed on the Form (or custom list). So the DataSource
of the BindingSource will be set to a Type and the BindingSource will create
a BindingList so you can setup everything in the designer. But even then
it's not a bad idea to assign the real DataSource (instance, not Type) at
Form load.
HTH,
Greetings
Jan 13 '06 #2

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

Similar topics

3
1935
by: Trammel | last post by:
Hi, I recently upgraded to VB.net from VB6.. and woah... I feel lost :¬O One of my reasons for upgrading is I was told that VB.net can do class inheritance and subclassing easier. Would someone be so kind as to provide a small demo about classes for some
1
12172
by: Leonardo | last post by:
Hi. I'm trying to build my first application with database access using VB 2005. I'm a VB 6 programmer and learning everything again has been challenging. I managed to write a code using some tips from a book I recently bought. The navigation works fine. My problem starts when it comes to adding new registers. I have three tables: clients, addresses and telephones, so the client can have multiple address and telephones. The client data is...
2
9645
by: Steve | last post by:
Hi- OK, I've got a DataGridView, I've created a BindingSource from one of my Business Entity object (based on generated classes from EntitySpaces) I've left the default column setup so that all the columns are displayed. My DataSource objects are composed like this: class Customer : esCustomer // where esCustomer is the EntitySpaces class that was generated
18
2205
by: Chris Hills | last post by:
A lesson in Posting How many C.L.C group posters does it take to change a C light bulb? 1 to change the light bulb and to post that the light bulb has been changed 14 to share similar experiences of changing light bulbs and how the light bulb could have been changed differently
2
3465
by: jehugaleahsa | last post by:
Hello: I have a BindingSource that has its DataSource set to a BindingList<Customerwhere Customer is a business object that manipulates a DataRow. All changes to a Customer instance, update a DataTable via DataRow. It is fairly easy to add a new item to the BindingSource. However, removing is a different story. I need to be able to know when an item is removed because I would like to call Delete on the DataRow. I need
1
3587
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hi misters, I used the Data Sources window to drop a custom object onto the designer surface. It created a BindingSource and BindingNavigator as a result. When I open the Properties window on the BindingSource, I see DataSource property set to the object I created.
2
4505
by: jehugaleahsa | last post by:
Hello: I'm working on improving some of our Windows Forms. I have created two user controls that I want to bind to the same BindingSource. I have an overview control that is used just to identify a customer. Then there is a details view that shows all their specifics. I wanted to keep navigation outside of my view. There is also a
5
4940
by: jehugaleahsa | last post by:
Hello: I am sure this question comes up a lot. I need to disable the controls on my Windows forms so that when the BindingSource is empty some the controls bound to it will be disabled. This will make it clear to the user that they have to create a new item first before they start working. This needs to be an easy process because there are many, many forms.
2
16847
by: Eric B. | last post by:
I could use a little clarification on using a BindingSource with my DataTable. As I understand it, the BindingSource sits between my data source (a DataTable) and DataGridView and any changes made to it is reflected in the other two? Now if that is so, how should I access the elements of my DataTable? I need to make decisions on what Rows to remove based on comparing the values of the elements. Should I access the individual elements via...
0
8868
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9389
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
9243
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9160
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9090
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
8063
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...
0
4504
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
3210
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
3
2149
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.