WinForms - Prevent ComboBox Mode Changing - DropDownList

In Winforms, what is the correct way to keep the user from changing the DropDown value? I want to prompt the user to say there are unsaved changes. If the user chooses not to discard these changes, I want to discard the combo box change. Any ideas on how to do this?

I, although I've seen the e.Cancel option before. But maybe not in System.Windows.Forms.ComboBox.

UPDATE : To further explain, the ComboBox is not part of the data entry form. It is used as a navigator / filter. The user made changes to the grid. I want them to be unable to navigate off the grid without getting prompted.

+2


source to share


3 answers


I'm not sure if I fully understand your question, but it seems that your question is not actually directly related to the ComboBox, but rather how to reset the form to its original values ​​when the user prefers not to save the changes they just made ...

Presumably you have a method on your form that loads controls from values ​​in some data structure (maybe an ORM or DataRow object). The easiest way to reset your form to its original (pre-edited) values ​​is to simply call this method again with the original (unchanged) data structure.



Update : well, an easy way to do this is to set the ComboBox Enabled property to a value false

as soon as they change anything on the form, and then set it back to true

as soon as they save or discard their changes.

+2


source


In the combined entry event, save the old value, enter the query to the user. If they decide to continue, don't do anything. If they decide to undo and not lose their changes, set the selected item to its old value.



+1


source


You might want to use the Validating event combo box, which is CancelEventHandler.

MSDN: Control.Validating Event

+1


source







All Articles