Click here to Skip to main content
15,917,565 members
Home / Discussions / C#
   

C#

 
GeneralRe: answer Pin
Gerry Schmitz29-Jul-20 23:03
mveGerry Schmitz29-Jul-20 23:03 
AnswerRe: answer Pin
Dave Kreskowiak29-Jul-20 11:14
mveDave Kreskowiak29-Jul-20 11:14 
AnswerRe: answer Pin
Eddy Vluggen30-Jul-20 0:50
professionalEddy Vluggen30-Jul-20 0:50 
AnswerRe: answer Pin
jsc4230-Jul-20 6:10
professionaljsc4230-Jul-20 6:10 
QuestionUser Control function C# Pin
Ismael_199928-Jul-20 4:46
Ismael_199928-Jul-20 4:46 
AnswerRe: User Control function C# Pin
Richard Andrew x6428-Jul-20 5:11
professionalRichard Andrew x6428-Jul-20 5:11 
GeneralRe: User Control function C# Pin
Ismael_199929-Jul-20 5:32
Ismael_199929-Jul-20 5:32 
GeneralRe: User Control function C# Pin
Gerry Schmitz29-Jul-20 7:11
mveGerry Schmitz29-Jul-20 7:11 
Some of this depends on your architecture, and whether it's Windows Forms or WPF / UWP; each use different patterns for validation.

If you only check validity on "save", you're doing "record-level" validation (easy) versus field-level validation (harder, due to cross-referencing and handling focus).

The "easy" way is to use a "data object" as the "view model" / transport between the "view" (form / window) and the "model" (data access layer / repository). This data object is used to pass data to the user control (to initialize the view / form / window) and to retrieve the "record" from the UC to be saved (add or update).

You may bind to the view model directly or copy the view data to it when saving. You then validate the data object and display the first error or save. If you have different "validation routines", you can pass a delegate (at initialize / load time) to the user control that accepts the data object and returns a status / error (if it's not feasible to have actually validation code in the user control.)

In the save "click" event, disable save (to avoid re-entrancy), copy the view / UC data to the view model (if not binding directly), validate, then save if OK or return an error. Reset buttons accordingly.

This pattern works for "Add" and "Update".

Deletes usually require some thinking about what to "display" after a delete and any further operations (like "add back in" or revert).
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food

GeneralRe: User Control function C# Pin
Ismael_199929-Jul-20 10:02
Ismael_199929-Jul-20 10:02 
GeneralRe: User Control function C# Pin
Gerry Schmitz30-Jul-20 0:10
mveGerry Schmitz30-Jul-20 0:10 
GeneralRe: User Control function C# Pin
Ralf Meier30-Jul-20 0:43
mveRalf Meier30-Jul-20 0:43 
GeneralRe: User Control function C# Pin
Ismael_199930-Jul-20 4:09
Ismael_199930-Jul-20 4:09 
GeneralRe: User Control function C# Pin
Gerry Schmitz30-Jul-20 7:21
mveGerry Schmitz30-Jul-20 7:21 
AnswerRe: User Control function C# Pin
Gerry Schmitz28-Jul-20 6:53
mveGerry Schmitz28-Jul-20 6:53 
AnswerRe: User Control function C# Pin
BillWoodruff28-Jul-20 16:55
professionalBillWoodruff28-Jul-20 16:55 
AnswerRe: User Control function C# Pin
Ralf Meier28-Jul-20 21:04
mveRalf Meier28-Jul-20 21:04 
GeneralRe: User Control function C# Pin
Ismael_199929-Jul-20 10:04
Ismael_199929-Jul-20 10:04 
GeneralRe: User Control function C# Pin
Ralf Meier29-Jul-20 20:30
mveRalf Meier29-Jul-20 20:30 
GeneralRe: User Control function C# Pin
Ismael_199930-Jul-20 4:03
Ismael_199930-Jul-20 4:03 
GeneralRe: User Control function C# Pin
Ralf Meier30-Jul-20 6:15
mveRalf Meier30-Jul-20 6:15 
GeneralRe: User Control function C# Pin
Ismael_199931-Jul-20 6:47
Ismael_199931-Jul-20 6:47 
GeneralRe: User Control function C# Pin
Gerry Schmitz31-Jul-20 7:48
mveGerry Schmitz31-Jul-20 7:48 
GeneralRe: User Control function C# Pin
Ismael_199931-Jul-20 10:36
Ismael_199931-Jul-20 10:36 
GeneralRe: User Control function C# Pin
Ralf Meier31-Jul-20 8:22
mveRalf Meier31-Jul-20 8:22 
GeneralRe: User Control function C# Pin
Ismael_199931-Jul-20 10:39
Ismael_199931-Jul-20 10:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.