Better way to check changed values

  • Thread starter Thread starter RP
  • Start date Start date
R

RP

In my Form, I have 20 or 30 Text Boxes and Combo Boxes. I am using a
tabbed interface. When the Form's Close button is clicked, I want to
check whether user attempted an entry in any of the Text Boxes or not.
If yes, a dialog box appears to ask whether user wants to Save the
entries or not.

There is also a data grid with one Code field that is a primary key.
Suppose, a user clicks on any row of the data grid, its column values
get filled in the above Text Boxes. If he changes any of the Text Box
values, then on Form Close when Save option is selected, the existing
record gets updated.

I don't want to use multiple flags and don't want multiple calls to
data-access layer. Any optimized way?
 
Hi,


And what happens if he select one row, change it and then select another
row?

You have to keep track of the changes anyway, I think that with only one
flag you could do it. Both before closing and when changing the selected row
you should check for this flag.
 
In my Form, I have 20 or 30 Text Boxes and Combo Boxes. I am using a
tabbed interface. When the Form's Close button is clicked, I want to
check whether user attempted an entry in any of the Text Boxes or not.
If yes, a dialog box appears to ask whether user wants to Save the
entries or not.

There is also a data grid with one Code field that is a primary key.
Suppose, a user clicks on any row of the data grid, its column values
get filled in the above Text Boxes. If he changes any of the Text Box
values, then on Form Close when Save option is selected, the existing
record gets updated.

I don't want to use multiple flags and don't want multiple calls to
data-access layer. Any optimized way?

I'm not sure why there'd be a need for multiple flags. What you care
about is if any of the values were changed, right? If any were changed,
you need to update the whole record, right? Then there's just one flag.

If you don't want to touch the database until the dialog is actually
dismissed, but _do_ want to track changes to any of the records the user
may have edited, then you could keep a running list of the records that
were changed, and the data for each. At the most basic, this could just
be a generic List<> that can store instances of the new data rows. I seem
to recall, however, a .NET class that acts as a sort of data table staging
area...sorry, I don't recall what it's called. With that, presumably you
wouldn't have to worry about managing duplicates in a List<>.

All that said, the DataGridView allows editing. If you've already got one
of those and are showing it to the user, why are you duplicating the
effort in a bunch of text boxes? Can't you just take advantage of the
DataGridView's editing behavior?

Pete
 

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

Back
Top