473,398 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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 9606
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**********************************@microsof t.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**********************************@microsof t.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**********************************@microsof t.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**********************************@microso ft.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 LogListBindingSource_AddingNew(ByVal sender As Object, ByVal e
As System.ComponentModel.AddingNewEventArgs) Handles
LogListBindingSource.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**********************************@microsof t.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**********************************@microsof t.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
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 -------------...
2
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...
3
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...
1
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...
4
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...
2
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...
7
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
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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,...

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.