adding data using DataGridView

B

BillE

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
 
R

RobinS

You can make a class that is a IBindingList(of object) where
object is your class and then bind that class to the DataGridView.
Not sure about the updates, though, as I haven't done that (yet).
You probably have to handle them yourself.

Robin S.
 
B

BillE

How would I add a new record with that?

RobinS said:
You can make a class that is a IBindingList(of object) where
object is your class and then bind that class to the DataGridView.
Not sure about the updates, though, as I haven't done that (yet).
You probably have to handle them yourself.

Robin S.
 
R

RobinS

Well, therein lies the rub. I have to figure out how to do this
in the next few days, too.

I'll probably try adding records to the grid and see what it
does to my business layer. It will probably raise an event
that I can handle and create a new instance of my class and
add it to the List. Or try changing records -- same thing,
I'll check and see if it propagates back to my BO.

And if I get frustrated and just want to get it done, I'll
pop up a form on top with all the fields on it, and let them
add/change/delete it from there, at which point I will
add, change, or delete the record from the List. Since the
grid is bound to the List, it will update automatically.

That's my theory. Do you have any brilliant ideas?

Robin S.
--------------------------------
 
B

BillE

I noticed that if I bind the dgv to a BindingSource control, when I type in
a new record in the dgv the 'AddingNew' event of the BindingSource fires.
The problem is that it fires when I first enter the new row before entering
new data, as well as when I leave the new row after entering new data, so it
is necessary to find some way to distinguish between the two before saving
the record. It seems clumsy to toggle a flag or something, there must be a
neat way to do this.
 
R

RobinS

In my class definition, I'm keeping a property for RowState. So I have
a theory that I can use that to determine whether an entry is deleted,
added, or updated, as long as I can figure out how to capture those
events.

I created my class last night, and the list of it inherits BindingList.
I created a data source (type=Object) using the wizard and dragged it
onto my form to create and bind my DGV. Then I have in my form_load
the load of the list (it runs the Create method).

The add and save buttons on the created binding list are greyed out,
but the delete button is not, so I whacked it, and sure enough one
of my rows disappeared.

Now, this is not cascading down to the underlying data source because
I haven't run EndEdit. Tomorrow I'll give that a try. (Going to MacWorld
today!).

I'm also going to my local .Net users group meeting tonight, and will
ask there if anybody has done this and see if I can get some free
advice. I'll report back.

This ought to be entertaining...
Robin S.
----------------------------------------
 
B

BillE

Thanks!

RobinS said:
In my class definition, I'm keeping a property for RowState. So I have
a theory that I can use that to determine whether an entry is deleted,
added, or updated, as long as I can figure out how to capture those
events.

I created my class last night, and the list of it inherits BindingList.
I created a data source (type=Object) using the wizard and dragged it
onto my form to create and bind my DGV. Then I have in my form_load
the load of the list (it runs the Create method).

The add and save buttons on the created binding list are greyed out,
but the delete button is not, so I whacked it, and sure enough one
of my rows disappeared.

Now, this is not cascading down to the underlying data source because
I haven't run EndEdit. Tomorrow I'll give that a try. (Going to MacWorld
today!).

I'm also going to my local .Net users group meeting tonight, and will
ask there if anybody has done this and see if I can get some free
advice. I'll report back.

This ought to be entertaining...
Robin S.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top