Welcome to Dream.In.Code
Become a C# Expert!

Join 150,394 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,040 people online right now. Registration is fast and FREE... Join Now!




Radiobutton Collection _CheckedChanged help

 
Reply to this topicStart new topic

Radiobutton Collection _CheckedChanged help, dont want to double-activate control

killnine
13 Mar, 2008 - 04:42 AM
Post #1

D.I.C Head
**

Joined: 12 Feb, 2007
Posts: 114



Thanked: 5 times
My Contributions
Hello everyone,
just a quick question. I have four radio buttons and only one of each can be selected. I want each of them to run a certain method when they are selected, but if I use "CheckedChanged", then the method will always run twice (one for the button that is losing its checkmark, and one for the button that is gaining it). This is really annoying and the method I am using utilizes hardware, so its expensive to do.

Thoughts on alleviating this problem? Thanks for the advice!

~K9
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Radiobutton Collection _CheckedChanged Help
13 Mar, 2008 - 08:57 AM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,327



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Cast the sender to a RadioButton and see if its Checked status is true. If it is then execute whichever method that RadioButton is supposed to execute. This way it will bypass a RadioButton that has been unchecked.

Here is an example of what I mean:
CODE

        private void radioButton_CheckedChanged(object sender, EventArgs e)
        {
            RadioButton radButton = (RadioButton)sender;

                if (radButton.Checked)
                {
                    // put code here to handle only when a
                    // radio button is checked
                }          
        }

User is offlineProfile CardPM
+Quote Post

killnine
RE: Radiobutton Collection _CheckedChanged Help
14 Mar, 2008 - 11:28 AM
Post #3

D.I.C Head
**

Joined: 12 Feb, 2007
Posts: 114



Thanked: 5 times
My Contributions
QUOTE(jayman9 @ 13 Mar, 2008 - 09:57 AM) *

Cast the sender to a RadioButton and see if its Checked status is true. If it is then execute whichever method that RadioButton is supposed to execute. This way it will bypass a RadioButton that has been unchecked.

Here is an example of what I mean:
CODE

        private void radioButton_CheckedChanged(object sender, EventArgs e)
        {
            RadioButton radButton = (RadioButton)sender;

                if (radButton.Checked)
                {
                    // put code here to handle only when a
                    // radio button is checked
                }          
        }




Thanks! The idea worked like a charm
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Radiobutton Collection _CheckedChanged Help
14 Mar, 2008 - 08:19 PM
Post #4

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,327



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Your welcome. Glad I could be of help.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 06:11PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month