Click here to Skip to main content
15,888,088 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have this snippet of code:

C#
if (!cboModel1.Text.Equals(string.Empty) || !cboVBrand1.Text.Equals(string.Empty) || !txtVType1.Text.Equals(string.Empty) || !cboChassis1.Text.Equals(string.Empty) || !lblPlate1.Text.Equals("### ###") || !txtVColor1.Text.Equals(string.Empty) || !cboSType1.Text.Equals(string.Empty) || !txtSPrice1.Text.Equals(string.Empty))
            {
                DialogResult change = MessageBox.Show("Discard entries and select an old vehicle?", "PROCEED?", MessageBoxButtons.YesNo);

                if (change == DialogResult.Yes)
                {
                    clearDisable_Old();
                    rdoOld.Checked = true;
                    rdoNew.Checked = false;
                }

                else
                {
                    rdoOld.Checked = false;
                    rdoNew.Checked = true;
                }
           }


I have two Radio Buttons: Old Vehicle and New Vehicle.
Initially the user has to select one of the radio buttons first before entering some data in the fields.
What I want to happen is when the user has clicked a radio button and entered some info in at least one field, when he suddenly clicks on the other radio button (suppose he changed his mind), there will be a prompt first so all the data he has entered won't be immediately cleared. What would be the event fit for this?
Posted

If this is Windows Forms I would use Validating[^] event since you need the ability to cancel the operation based on the user input.

The CancelEventArgs[^] has a property Cancel which can be set to true to prevent the radio button from changing it's state.
 
Share this answer
 
None. That is actually one of the worst design ideas I ever heard of. But, what's about an event? First of all, it's apparent that you cannot do any handling just "before clicking", just because the "clicking" had not yet happened.

In practice, there are always some events preceding a click. For example, before you click something with the mouse you invoke the "mouse enter" event and few "mouse move" events. But the use can "click" without a mouse: the "click" event is purely functional, this is an action performed in different ways: mouse, keyboard, even programmatical one (which I would not recommend). You can handle "got focus" event (you mentioned something similar), but it's possible to "click" a control without focusing it.

More importantly, all those events cannot be used in principle, because they all may not lead to an actual click: the user can just play around with the mouse and the control focus. This possibility is the fundamental user right, you should never take it out. Say, on all changes on focus or, say, selections, you can show different information on status line, or something similar, but never anything modal; same goes about moving the mouse. Breaking this simple rule will drive the users crazy, people will never agree to use your software.

If you want some design advice, you have to formulate your ultimate goal. It should really be ultimate, that is, you should not put any events and similar technical detail in the formulation of your problem.

—SA
 
Share this answer
 
Comments
kmllev 29-Jul-15 2:08am    
So do you think I should just opt for another control, say, a ComboBox instead?
Sergey Alexandrovich Kryukov 29-Jul-15 2:12am    
You can, but don't try to do anything "before click". You can use the selection change event, and instead of "click", uses say double click, and Enter and (importantly, to give alternative control with visual feedback), a button.
-SA

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