[c#] how do I get my new object from bound DataGridView

lozina

Lifer
Sep 10, 2001
11,711
8
81
I am first time using DataGridView and I bound it to a BindingList of my object

Now, I got everything displaying fine but I have a problem with creating new rows via the grid, which I want to do.

The thing is, when I enter the new row (the one with an asterisk next to it) the grid automatically instantiates a new instance of my object. I know this because it hits a break point in it's constructor.

However I have no idea how to get a hold of this new object or to execute my own code when this occurs. All I can find is the event OnNewRowNeeded which only seems to trigger when I leave focus. I can use OnRowEnter and from the Row object I can tell that IsNewRow is true but I was hoping the property DataBoundItem held that new instance the grid created but it does not. That property is null and I cannot find that automatically generated object anywhere

How do I get a handle on that new object ?
 

lozina

Lifer
Sep 10, 2001
11,711
8
81
Ah I see the error in my ways.

I am supposed to implement the AddingNew event on my BindingList... now it all makes sense!