2

i have datagridview and column in it,and type is combobox.Combobox value's are used from sql data base.In combobox "Status" i have 5 different item value's.What i want is that when i change item value from combobox and press "save" button ,i want to check which value was before this one(before save) and say:

private void m02BindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
    try
    {
        if (StatusTextBox.Text == "3" && // + want to ask here if previous statusTextBox.text was "1" then to execute lines down if not goes to 'else')
        {
            DialogResult mbox = MessageBox.Show("do you want to save today's  date and time?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            datumOtvaranjaDateTimePicker.Focus();
            if (mbox == DialogResult.Yes)
            {
                datumOtvaranjaDateTimePicker.Value = DateTime.Now;
            }
            Save();
            Refresh();
        }
        else
        {
            MessageBox.Show("you cant do that!!!" + Environment.NewLine + "Check what you typed and try again", "Upozorenje", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            Refresh();
        }
    }
    catch (Exception)
    {

    }
}
Kieran Quinn
  • 1,085
  • 2
  • 22
  • 49

1 Answers1

0

Look at this other answer

You can handle the ComboBox.Enter event. Then save off the SelectedItem or SelectedValue to a member variable

public partial class Form1 : Form 
{
    public Form1()
    {
        InitializeComponent();
        comboBox1.Enter += comboBox1_Enter;
    }

    private void comboBox1_Enter(object sender, EventArgs e)
    {
        m_cb1PrevVal = comboBox1.SelectedValue;
    }

    private void RestoreOldValue()
    {
        comboBox1.SelectedValue = m_cb1PrevVal;
    }
}
Community
  • 1
  • 1
faby
  • 7,394
  • 3
  • 27
  • 44