Hello:
I am using WinGrid .Net v2.0.20062.60510.
The grid displays the data from a table where FirstName is mandatory.
I do a dsDataSet.Update on the _AfterRowUpdate event.
While I add data to the phantom row at the bottom of the grid, and supply thr required data, when I click on an existing row, the databse is updated with no errors.
However, when I click on the new Phantom Row, I get an error message "First Name is mandatory". But the row does get updated in the table.
Can somebody tell my what I am doing wrong?
I assume that by "the phantom row" you are referring to the TemplateAddRow.
As soon as you click on the TemplateAddRow, it becomes an AddRow and a new AddRow is added to the grid's DataSource. So if you call Update on your DataSet at this point, you are trying to save 2 rows, not just one.
I don't see any way around this. By placing the focus in the AddNewRow, you are essentially in the middle of an edit of a new row and that row is part of the data source, so it will try to get saved.
It's probably not a good idea to try to update the back end after each individual row update. The DotNet framework is set up to do updates in batches, not one at a time.
Mike:
Thanks for your reply.
The user wants an implicit save every time the row is changed.
Is there any event that Wingrid supports that enables me to save data on BeforeRow Change event?
If there's one such, I can see if there are changes to the dataset and if so, issue an update.
Venki
Hi Venki,
Maybe you could try using AfterRowDeactivate instead of AfterRowUpdate. Or BeforeRowUpdate might be an option, also... although that's probably not a great idea.
Another option which is something of a hack might be to try canceling the AddNew in the grid and then re-adding it after the update is complete. So you would check in AfterRowUpdate if the ActiveRow in the grid's IsUnmodifiedTemplateAddRow is true, and if so, call CancelUpdate, then Update the DataSet, then put focus back into the appropriate cell in the TemplateAddRow again.
I see that there is no AfterRowDeactivate event. But your suggestion lit a lght bulb in my mind.
I used the BeforeRowDeactivate event to see if there are uncommitted changes in the data set and if so, then update the changes.
ugPatient.BeforeRowDeactivate
Sub
This gives me the desired bahavior. Thanks.
That makes sense. :)