What to do with the last record in Grid!

What to do with the last record in Grid!

Old forum URL: forums.lhotka.net/forums/t/2753.aspx


Mahmud posted on Monday, April 23, 2007

First of all...this is our first project using CSLA. We are developing Windows Forms project in C# VS 2005. Now, for the simple tables we are using BusinessListBase bound to a GridView through BindingContext. Lets say there are two fields in a table. For the first field (property), we generate the ID by incrementing 1 (as seen in ProjectTracker sample). The next field will be entered by user.

Now, lets say the user is entering records in the grid. When user presses enter in the second field, the focus moves to the last line of grid, and a new ID is generated. But the user does not want to add more records - so if he presses save, the errorprovider says that you cant have blank 'field2'.

How to solve the issue, or how can I check that the last data only has ID generated but no editing done by user - so then I can discard the last record while saving.

I will have a series of questions coming...

 

 

Bayu replied on Monday, April 23, 2007

Hey,

Perhaps you could have a look at this thread where someone mentioned that he 'trapped' the user in the gridrow as long as the input on that particular row is not valid.

The idea would be that your users can never leave a row with invalid fields, either they input valid data or they back out by pressing escape.

Bayu

Mahmud replied on Wednesday, April 25, 2007

I would look at the DataError event of the grid. But, actually my problem was not that - the user have done anything wrong. After pressing <ENTER> at the last column of the grid, the cursor moves to the next line of the grid - and we have generated a new ID for the primary key property. The user just wants to save his own record. How can I undo the last generated record from the grid and also from the businesslistbase class.

One quick question - does the gridview columns have UpdateMode property? For the grid columns I also want OnPropertyChanged instead of OnValidate to be set...where do I do that?

ajj3085 replied on Thursday, April 26, 2007

Well, pressing enter has a defined behavior of creating a new row.  If the user wants to save, they should just go to hit the save button, not press enter to start a new row.

That said, typically pressing ESC will remove the row just entered.  In the Infragistics grid though, you need to ESC twice for some reason.

Copyright (c) Marimer LLC