Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all i have written the following code

MSIL
private void btnEntry_Click(object sender, EventArgs e)
        {

            if (cmbServiceClassCode.SelectedIndex == -1 || txtCompname.Text == string.Empty || txtCompidentification.Text == string.Empty
                || cmbStandardentryclasscode.SelectedIndex == -1 || txtOrgstatuscode.Text == string.Empty || txtODFIidentification.Text == string.Empty
                || txtBatchno.Text == string.Empty)
            {
                MessageBox.Show("Insufficient Data to Proceed");
                if (Convert.ToBoolean(DialogResult.OK))
                {
                    this.Show();
                }
            }

            string s = cmbStandardentryclasscode.SelectedItem.ToString();
            try
            {

                if (s == "CCD")
                {
                    frmEntryDetails frmentry = new frmEntryDetails(s);
                    frmentry.ShowDialog(this);
                }
                else
                {
                    frmEntryDetails frmentry = new frmEntryDetails(s);
                    frmentry.ShowDialog(this);
                }
            }


            catch (Exception ex)
            {

            }

        }


But if i select some value cmbStandardentryclasscode the error message is displayed but executing the remaining code. So can any one please help me.
Posted
Updated 3-Sep-10 19:09pm
v2
Comments
Sandeep Mewara 4-Sep-10 2:52am    
What error?
demouser743 4-Sep-10 3:11am    
I am not getting an error first it is executing If condition which was written first. If i have any value selected from combobox and if i left the other empty the messagebox is getting displayed and the remaining code executes. What i need is if the first if fails the second condition should not get executed

Do you not want the following structure then (i.e.add an else);

private void btnEntry_Click(object sender, EventArgs e)
        {
            if ( //the condition checks)
            {
                MessageBox.Show("Insufficient Data to Proceed");
                if (Convert.ToBoolean(DialogResult.OK))
                {
                    this.Show();
                }
            }
            else
            {
                string s = cmbStandardentryclasscode.SelectedItem.ToString();
                try
                {
                    //code as per existing try
                }
            
                catch (Exception ex)
                {
                }
           }
        }
 
Share this answer
 
v2
Ok i got the answer


Edited the code as follows


MSIL
private void btnEntry_Click(object sender, EventArgs e)
        {

            if (cmbServiceClassCode.SelectedIndex == -1 || txtCompname.Text == string.Empty || txtCompidentification.Text == string.Empty
                || cmbStandardentryclasscode.SelectedIndex == -1 || txtOrgstatuscode.Text == string.Empty || txtODFIidentification.Text == string.Empty
                || txtBatchno.Text == string.Empty)
            {
                MessageBox.Show("Insufficient Data to Proceed");
            }

            try
            {
                string s = cmbStandardentryclasscode.SelectedItem.ToString();

                if (s != null  && cmbServiceClassCode.SelectedIndex == -1 || txtCompname.Text == string.Empty
                    || txtCompidentification.Text == string.Empty || txtOrgstatuscode.Text == string.Empty || txtODFIidentification.Text == string.Empty)
                {
                    this.Show();
                }

                else
                {
                    if (s == "CCD")
                    {
                        frmEntryDetails frmentry = new frmEntryDetails(s);
                        frmentry.ShowDialog(this);
                    }
                    else
                    {
                        frmEntryDetails frmentry = new frmEntryDetails(s);
                        frmentry.ShowDialog(this);
                    }
                }
            }

            catch (Exception ex)
            {

            }
        }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900