Click here to Skip to main content
15,887,363 members
Home / Discussions / C#
   

C#

 
GeneralRe: Checking required fields in a second Windows Form Pin
JTRizos29-Oct-09 6:24
JTRizos29-Oct-09 6:24 
AnswerRe: Checking required fields in a second Windows Form Pin
_Madmatt26-Oct-09 9:43
_Madmatt26-Oct-09 9:43 
GeneralRe: Checking required fields in a second Windows Form Pin
Not Active26-Oct-09 9:59
mentorNot Active26-Oct-09 9:59 
GeneralRe: Checking required fields in a second Windows Form Pin
_Madmatt27-Oct-09 9:45
_Madmatt27-Oct-09 9:45 
GeneralRe: Checking required fields in a second Windows Form Pin
Not Active27-Oct-09 10:10
mentorNot Active27-Oct-09 10:10 
GeneralRe: Checking required fields in a second Windows Form Pin
_Madmatt27-Oct-09 10:20
_Madmatt27-Oct-09 10:20 
GeneralRe: Checking required fields in a second Windows Form Pin
Not Active27-Oct-09 10:40
mentorNot Active27-Oct-09 10:40 
QuestionRe: Checking required fields in a second Windows Form [modified] Pin
JTRizos27-Oct-09 11:49
JTRizos27-Oct-09 11:49 
I am guessing this recent interchange of messages must be part of another thread.

But since you've responded in this one. I still have an issue that I cannot for the life of me figure out. Your input has been helpful but I cannot get around the problem of the code in Form2 checking for empty textboxes twice and then falling through to the rest of the code in Form1. I run Debug and cannot find the cause. A similar If/Else in Form1 returns to Form1 focused on field 1 if the conditions find that a required field is empty. It continues to do this until I fill all the required fields or hit Exit.

Similar code in Form2 only checks twice, finds/reports the correct empty textboxes and then drops down back to Form1 regardless whether the textboxes are empty or not. The returns in Form2 do not seem to affect anything. Here's some of the code:

Form1.cs
--------
{
MessageBox.Show("The Last Name and First Name are required!!");
return;
}
//  Above code handles Form1 textboxes


//Call Form2 for CaseNo and Reason data
GetForm2();
...
...


// Opens second Diaolog form (Form2) to get Case Number and Reason
  public void GetForm2()
  {
      Form2 qForm = new Form2();
      qForm.ShowDialog();

      if (qForm.ShowDialog()== DialogResult.OK)
      {
          CaseNo = qForm.CaseNo;
          Reason = qForm.Reason;
          MessageBox.Show("Form2 Exists" + " " + CaseNo + "  " + Reason);
      }
      qForm.Dispose();
  }


Form2.cs
--------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DMV_Test_1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
                InitializeComponent();
        }

        public string CaseNo
        {
            get { return textBox1.Text; }
        }
        public string Reason
        {
            get { return textBox2.Text; }
        }
        
   
        private void button1_Click(object sender, System.EventArgs e)
        {
            if (CaseNo == "")
            {
                MessageBox.Show("The Case No is required!!");
                this.textBox1.Focus();
                return;
            }

            else
            if (Reason == "")
            {
                MessageBox.Show("The Reason is required!!");
                this.textBox2.Focus();
                return;
            }
            else
            {
                this.DialogResult = DialogResult.OK; Close();
            }  
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;    Close();
        }
    }
}


Seems so simple (has been so far) but this just really frustrates me. Confused | :confused: Any ideas, gotchas, tips, etc. will be much appreciated. BTW, I did this in Visual Studio 2005 IDE with very little code from me to design and set up the forms. Great tool.

Thanx again

modified on Tuesday, October 27, 2009 6:14 PM

AnswerRe: Checking required fields in a second Windows Form Pin
Not Active27-Oct-09 14:50
mentorNot Active27-Oct-09 14:50 
GeneralRe: Checking required fields in a second Windows Form Pin
JTRizos28-Oct-09 5:57
JTRizos28-Oct-09 5:57 
GeneralRe: Checking required fields in a second Windows Form Pin
Not Active28-Oct-09 9:20
mentorNot Active28-Oct-09 9:20 
AnswerRe: Checking required fields in a second Windows Form Pin
JTRizos29-Oct-09 11:19
JTRizos29-Oct-09 11:19 
GeneralRe: Checking required fields in a second Windows Form Pin
Not Active29-Oct-09 11:29
mentorNot Active29-Oct-09 11:29 
GeneralRe: Checking required fields in a second Windows Form Pin
_Madmatt28-Oct-09 6:09
_Madmatt28-Oct-09 6:09 
GeneralRe: Checking required fields in a second Windows Form Pin
JTRizos28-Oct-09 6:35
JTRizos28-Oct-09 6:35 
GeneralRe: Checking required fields in a second Windows Form Pin
_Madmatt28-Oct-09 9:02
_Madmatt28-Oct-09 9:02 
GeneralRe: Checking required fields in a second Windows Form Pin
Not Active28-Oct-09 9:25
mentorNot Active28-Oct-09 9:25 
GeneralRe: Checking required fields in a second Windows Form Pin
_Madmatt28-Oct-09 9:33
_Madmatt28-Oct-09 9:33 
GeneralRe: Checking required fields in a second Windows Form Pin
Not Active28-Oct-09 10:18
mentorNot Active28-Oct-09 10:18 
GeneralRe: Checking required fields in a second Windows Form Pin
_Madmatt28-Oct-09 20:59
_Madmatt28-Oct-09 20:59 
GeneralRe: Checking required fields in a second Windows Form Pin
Not Active29-Oct-09 11:37
mentorNot Active29-Oct-09 11:37 
GeneralRe: Checking required fields in a second Windows Form Pin
_Madmatt29-Oct-09 20:44
_Madmatt29-Oct-09 20:44 
GeneralRe: Checking required fields in a second Windows Form Pin
Not Active28-Oct-09 1:16
mentorNot Active28-Oct-09 1:16 
GeneralRe: Checking required fields in a second Windows Form Pin
_Madmatt28-Oct-09 6:10
_Madmatt28-Oct-09 6:10 
GeneralRe: Checking required fields in a second Windows Form Pin
EliottA29-Oct-09 6:53
EliottA29-Oct-09 6:53 

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.