What's wrong with my code?

What's happening when the program suddenly stopped There's no exception. all the controls are not responsive except for the toolstrip buttons. after I delete and then click new, or after save then new.


Answer this question

What's wrong with my code?

  • Damian Coverly

    icemart525 wrote:
    What's happening when the program suddenly stopped There's no exception. all the controls are not responsive except for the toolstrip buttons. after I delete and then click new, or after save then new.

    I found out what's causing this problem, it's my bound quantityTextBox. This happens when the focus leaves the textbox and the text property is empty. I didn't declare a lost focus event so why it's validating



  • Boba_Phatt

    my textbox is bound to an int type, AllowDBNull is set to false, I don't have codes related to this textbox.

    i have my own Add New and Save buttons.

    here are my save methods

    private void SaveOrder()

    {

    if (pONoTextBox.Text == "")

    {

    MessageBox.Show("PONo field is required.", "Warning", MessageBoxButtons.OK,

    MessageBoxIcon.Warning);

    pONoTextBox.Focus();

    }

    else if (qtyTextBox.Text == "")

    {

    MessageBox.Show("Qty field is required.", "Warning", MessageBoxButtons.OK,

    MessageBoxIcon.Warning);

    qtyTextBox.Focus();

    }

    else if (unitOrderTextBox.Text == "")

    {

    MessageBox.Show("Unit Order field is required.", "Warning", MessageBoxButtons.OK,

    MessageBoxIcon.Warning);

    unitOrderTextBox.Focus();

    }

    else if (productIDComboBox.SelectedValue == null)

    {

    MessageBox.Show("Product field is required.", "Warning", MessageBoxButtons.OK,

    MessageBoxIcon.Warning);

    productIDComboBox.Focus();

    }

    else if (clientIDComboBox.SelectedValue == null)

    {

    MessageBox.Show("Client field is required.", "Warning", MessageBoxButtons.OK,

    MessageBoxIcon.Warning);

    clientIDComboBox.Focus();

    }

    else

    {

    if (Martti.GlobalVars.flag == 1000)

    {

    if (Mode == "New")

    {

    InsertOrder();

    }

    else if (Mode == "Old")

    {

    UpdateOrder();

    }

    }

    MessageBox.Show("Done!", "OPR SYSTEM", MessageBoxButtons.OK,

    MessageBoxIcon.Information);

    Mode = "Old";

    bindingNavigatorDeleteItem.Enabled = true;

    bindingNavigatorAddNewItem.Enabled = true;

    btnFind.Enabled = true;

    btnCancel.Enabled = false;

    RefreshOrder();

    }

    }

    private void InsertOrder()

    {

    this.tblOrderTableAdapter.Insert(pONoTextBox.Text, int.Parse(qtyTextBox.Text),

    unitOrderTextBox.Text, (int)productIDComboBox.SelectedValue,

    (int)clientIDComboBox.SelectedValue, dateDateTimePicker.Value.Date, 0);

    }

    private void UpdateOrder()

    {

    this.tblOrderTableAdapter.UpdateByOrderID(pONoTextBox.Text, int.Parse(qtyTextBox.Text),

    unitOrderTextBox.Text, (int)productIDComboBox.SelectedValue, (int)clientIDComboBox.SelectedValue,

    dateDateTimePicker.Value.Date, int.Parse(orderIDTextBox.Text));

    }

    private void RefreshOrder()

    {

    if (orderIDTextBox.Text == "")

    {

    this.tblOrderTableAdapter.FillByAll(this.dbOPRDataSet.tblOrder, pONoTextBox.Text,

    int.Parse(qtyTextBox.Text), unitOrderTextBox.Text, (int)productIDComboBox.SelectedValue,

    (int)clientIDComboBox.SelectedValue, dateDateTimePicker.Value.Date);

    }

    else

    {

    this.tblOrderTableAdapter.FillByOrderID(this.dbOPRDataSet.tblOrder, int.Parse(orderIDTextBox.Text));

    }

    }

    my AddNew methods

    private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)

    {

    // set flag for addnew click event

    Martti.GlobalVars.flag = 1000;

    Martti.GlobalVars.TestValue = "AddOrder";

    Mode = "New";

    ClearItems();

    EnableControls();

    pONoTextBox.Focus();

    }

    private void ClearItems()

    {

    orderIDTextBox.Text = "";

    pONoTextBox.Text = "";

    qtyTextBox.Text = "";

    unitOrderTextBox.Text = "";

    productIDComboBox.Text = "";

    clientIDComboBox.Text = "";

    }

    the error occurs when i save then addnew. the focus won't leave the int textbox.



  • AnandAsir

    I think you're going to have to provide more information before we can be of much use. Things like what are you binding to Is there any validation code in the data source Are there other events in the TextBox that have handlers Yours is the type of question that is really a debugging exercise, so we'll need to see some code to help out.



  • Akd02

    Hi

    I think the TextBox that is bound to the Column is NOT Null so why it is causing error.



  • What's wrong with my code?