473,654 Members | 3,033 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding new row to DataGridView bound to Custom Object

I have a DataGridView bound to a collection of Custom Objects. I have
enabled adding new rows, but since my object does not have a public
constructor (it uses a factory method), I get an error when I attempt to
enter the new row. My guess is that I need to override some method so that I
can create the object for the grid. But for the life of me, and I can't find
it. Can someone point me in the right direction?
--
Terry
Nov 7 '07 #1
4 9624
Terry,

Have you tried just inserting a new row into the data source of the
DataGridView object?

Brendon

"Terry" <Te****@nospam. nospamwrote in message
news:3E******** *************** ***********@mic rosoft.com...
>I have a DataGridView bound to a collection of Custom Objects. I have
enabled adding new rows, but since my object does not have a public
constructor (it uses a factory method), I get an error when I attempt to
enter the new row. My guess is that I need to override some method so
that I
can create the object for the grid. But for the life of me, and I can't
find
it. Can someone point me in the right direction?
--
Terry
Nov 7 '07 #2
Hi,
No, I haven't. Are you suggesting that I pre-create a new object and
have it in the grid just in case the user wants to add one? I suppose that
that could be made to work. I still have to believe that there is some
method that I can override or some event I can subscribe to, that would allow
me to create the object for the grid.
--
Terry
"Brendon Bezuidenhout" wrote:
Terry,

Have you tried just inserting a new row into the data source of the
DataGridView object?

Brendon

"Terry" <Te****@nospam. nospamwrote in message
news:3E******** *************** ***********@mic rosoft.com...
I have a DataGridView bound to a collection of Custom Objects. I have
enabled adding new rows, but since my object does not have a public
constructor (it uses a factory method), I get an error when I attempt to
enter the new row. My guess is that I need to override some method so
that I
can create the object for the grid. But for the life of me, and I can't
find
it. Can someone point me in the right direction?
--
Terry
Nov 7 '07 #3
Terry,

No what you want to do do is inefficient... when they add a new "row" as it
were you create a new datadow and add that data row to the datasource which
is a DataTable (sucking it from my head now so could be wrong on the type).
Then when they close/save then you save and add the new row as per normal to
your DB... Why don't you look into the BindingManager and BindingSource also
:) it will help and might make you rethink things slightly.

Brendon

"Terry" <Te****@nospam. nospamwrote in message
news:84******** *************** ***********@mic rosoft.com...
Hi,
No, I haven't. Are you suggesting that I pre-create a new object and
have it in the grid just in case the user wants to add one? I suppose
that
that could be made to work. I still have to believe that there is some
method that I can override or some event I can subscribe to, that would
allow
me to create the object for the grid.
--
Terry
"Brendon Bezuidenhout" wrote:
>Terry,

Have you tried just inserting a new row into the data source of the
DataGridView object?

Brendon

"Terry" <Te****@nospam. nospamwrote in message
news:3E******* *************** ************@mi crosoft.com...
>I have a DataGridView bound to a collection of Custom Objects. I have
enabled adding new rows, but since my object does not have a public
constructor (it uses a factory method), I get an error when I attempt
to
enter the new row. My guess is that I need to override some method so
that I
can create the object for the grid. But for the life of me, and I
can't
find
it. Can someone point me in the right direction?
--
Terry
Nov 7 '07 #4
Ok, turned out to be fairly easy - once I figured out where to do it!
The grid is bound to a bindingsource which raises a 'AddingNew' event. So
the code looks like...
Private Sub LogListBindingS ource_AddingNew (ByVal sender As Object, ByVal e
As System.Componen tModel.AddingNe wEventArgs) Handles
LogListBindingS ource.AddingNew

e.NewObject = Log.Create(Id)

End Sub
--
Terry
"Brendon Bezuidenhout" wrote:
Terry,

No what you want to do do is inefficient... when they add a new "row" as it
were you create a new datadow and add that data row to the datasource which
is a DataTable (sucking it from my head now so could be wrong on the type).
Then when they close/save then you save and add the new row as per normal to
your DB... Why don't you look into the BindingManager and BindingSource also
:) it will help and might make you rethink things slightly.

Brendon

"Terry" <Te****@nospam. nospamwrote in message
news:84******** *************** ***********@mic rosoft.com...
Hi,
No, I haven't. Are you suggesting that I pre-create a new object and
have it in the grid just in case the user wants to add one? I suppose
that
that could be made to work. I still have to believe that there is some
method that I can override or some event I can subscribe to, that would
allow
me to create the object for the grid.
--
Terry
"Brendon Bezuidenhout" wrote:
Terry,

Have you tried just inserting a new row into the data source of the
DataGridView object?

Brendon

"Terry" <Te****@nospam. nospamwrote in message
news:3E******** *************** ***********@mic rosoft.com...
I have a DataGridView bound to a collection of Custom Objects. I have
enabled adding new rows, but since my object does not have a public
constructor (it uses a factory method), I get an error when I attempt
to
enter the new row. My guess is that I need to override some method so
that I
can create the object for the grid. But for the life of me, and I
can't
find
it. Can someone point me in the right direction?
--
Terry
Nov 8 '07 #5

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

Similar topics

1
12307
by: ME | last post by:
I was running into a problem with the DataGridView while binding it to an object Collection. I got it working and I thought others might like to know how. -------------- Problem ------------- The grid was bound to a simple object collection. The object contained string and decimal properties, nothing to fancy. When an item was added to the collection I would databind as follows (this happened on each item "Add"):
2
529
by: mark carew | last post by:
Hi All DataGridView Users. I have noticed that there seems to be very little useful response to DataGridView questions in this news group. I have looked at the spanish, belgium, french, italian equivalent CS newsgroups and the situation would appear to be much the same. Why this is the case, who knows? But, I have found one link that may be of help in understanding the innards of DataGridView.
3
8375
by: WayDownUnder | last post by:
I have a datagridview that is bound to a cutom collection. The classes contained in the custom collection have the properties that are bound to the class . This works fine ! But if one of the properites exposes another object I would like to bind a property of the sub object to the DataPropertyName this does not seem to work. eg main object customer has a property called Address which is a contained object inside object Address there...
1
7508
by: WayDownUnder | last post by:
I have a datagridview that is bound to a cutom collection. The classes contained in the custom collection have the properties that are bound to the class . This works fine ! But if one of the properites exposes another object I would like to bind a property of the sub object to the DataPropertyName this does not seem to work. eg main object customer has a property called Address which is a contained object inside object Address there...
4
7271
by: Chris Botha | last post by:
VS2005 and I have a DataTable displayed in a DataGridView that needs custom sorting, with the DataSource of the grid set to the DataTable and the SortCompare event just won't fire. Then I found this in the docs "This event occurs only when the DataSource property is not set and the VirtualMode property value is false" This seems really odd but may be true. I can't see what the purpose of this event is then, how else will one use the...
2
9642
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
7
7336
by: BillE | last post by:
What is the best way to add data using a DataGridView in a multi-tier application (data entry is handled in a data access layer using stored procedures)? Thanks Bill
3
9681
by: jehugaleahsa | last post by:
Hello: I am binding a DataGridView with a BindingList<T>, where T is a custom business object that implements INotifyPropertyChanged. When you bind a DataGridView to a DataTable, it has this cool little feature - it will not call DataTable.Rows.Add until after you leave the DataGridView row. This is cool because it lets your user edit the record as much as needed to get it into a valid state before actually adding it to the DataTable.
0
5646
by: priyamtheone | last post by:
I'm trying to make a datagridview column to act like a datetimepicker column (C#.Net 2005). These are the behaviours that the dgv should have: 1) Initially all the cells of the dtp column should be blank unless they are filled by the user. 2) As soon as the user enters a cell, the dtp control should appear as the editing control of that cell. If there's a value in the cell beforehand, that value is set as the value of the dtp editing control...
0
8285
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
8706
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
8475
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
8591
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...
1
6160
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
5621
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
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...
0
4293
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2709
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

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.