I would suggest you use an OK/Cancel button system, as while an item could even be considered valid, doesnt mean the user doesnt want to change it - it also means you only have 2 ways of leaving your form, the buttons or they hit close.
LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
if ((dlg.nameText.Length > 5) || (dlg.nameText.Length < 8))
This is always true!
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
Yes.
dont set it to ok when its not :P
The thing is thats exactly what you're doing
You're doing a number of tests on clicking an OK button. ALL of those tests must pass before you can move on, not just 1.
Either you have to make your if a big big if, or you do your logic so that if 1 of the tests fails you can tell. Easiest way to do that, is set the a boolean to false, and set it to true if any condition fails.. then at the end move on if its still false.
LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
You normally don't set DialogResult.OK yourself. You get it after pressing an OK button or something.
Like so :
if(this.DialogResult == DialogResult.OK)
>>check textboxes, if not ok set DialogResult to None or Cancel
else
>>
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
Renukavani, that code could be made so much simpler - which is why i didnt post code, because people need to understand not just copy
LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
Besides what LizR said, your else clauses never get executed for reasons I mentioned earlier...
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
Set the dialog result to someting *ONLY* if all conditions are met.
LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190