Question Locked

How do I capture a row adding event in a datagrid?

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I am loading data from an sql database into a grid. I want to be able to add rows to the data and save them back to the database. I am able to do that right now but want I want to do is to have some of the data from the previous row loaded into the new row so that it doesn't have to be manually entered.

The data in the grid is loaded by certain criteria and I would like to have that criteria put in the right fields for me before actual editing on the new row begins. The only way I can think of to do this is when the row is created but I haven't been able to find any way to capture that event.

I am using VB.net 2003 with the .NET 1.1 Framework.

Can anyone help?
Thanks JV

6 replies

by jvoyles

This looks like it happens after you have updated the grid and are applying the updates to the database. I have tried capturing the updating row event of the datatable but that seems to happen after the row in the grid is being added to the datatable also.

Is there anyway I can put some values in as the row displayed in the datagrid is created before it is displayed?

by jvoyles

I guess I could just leave those fields blank and fill them in as the update to the database is taking place. Not the way I really wanted to do it but it could work.

by tony hopkinson

Row updatingevent has a statementtype property of insert. detect that fill in the ditto's post the change and go into edit.

Does the user have to hit a button for the insert ?

You could just insert the data into the table with a db copmmand and then make the control refresh. Watch for sort order on that though.

by jvoyles

I have set those columns to be hidden or read only on the grid since I really don't want the use to update them anyway as they are used for indexing. I am allowing the user to make all the edits they need and then doing one update to the database by having them press an update button. Then I am checking for any added rows to the dataset and putting the data in there before the update to the database.

Thank you though for all your help. It was while I was looking into the rowupdating event that I figured out how to check the status on the rows in the dataset and decided to do it that way.

Once again thanks for your help, it's working great now.

JV

This discussion is closed to new replies.