Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
740
Set the previous value of the UltraComboEditor after validation
posted

Hi everyone,

I have a UltraComboEditor which has a list of recipients. And when the form is loaded, for each Note (Form contains the Note Details), there will be a already a recipent loaded from the database. e.g. Amy is selected for loaded Note.

There will be a validation, if I select another recipient from the list, it will pop up a message saying "Do you wish to reforward this note to Andrew?", which "Andrew" is the newly selected recipient. If I say "Yes" , the combo value will be set to "Andrew", and save to database, or else it  should be set back to the previous value which is "Amy".

My problem is when i put the following coding in the ValueChanged event, the message will pop up twice, since i set the selectedIndex back to the original. And also this event fires at the form loading where I load up the combo with the recipient.

Loading Data

==========

private void frmNotes_Load(object sender, EventArgs e)

{

// I removed the events at the begining otherwise the message pops up when loading the Combo

uceMessageSentTo.ValueChanged -=
new EventHandler(uceMessageSentTo_ValueChanged);

DisplayData();

_recipientIdex = uceMessageSentTo.SelectedIndex;

uceMessageSentTo.ValueChanged +=
new EventHandler(uceMessageSentTo_ValueChanged);

}

private void uceMessageSentTo_ValueChanged(object sender, EventArgs e)

{

DialogResult result = MessageBox.Show("Do you wish to send this note to " + uceMessageSentTo.Text + "?", "Change Recipient",

MessageBoxButtons.YesNo, MessageBoxIcon.Question);

if (result == DialogResult.Yes)

{

// Save to database

}

else

{

uceMessageSentTo.SelectedIndex = _recipientIdex;

}

}

Can someone please suggest a solution to resolve this probelm. Urgent Help needed !

Thanks in Advance,

NW

 

Parents
  • 37774
    posted

    Since you know all of the places that you're going to cause the ValueChanged to be fired again, you could just keep a flag to bail out of the ValueChanged event handler while you're setting the SelectedIndex so that you don't repeat the logic.

    -Matt

Reply Children
No Data