Checked and Checkedchanged.

Posted on 2006-05-02
Last Modified: 2008-03-04
In VB Radio button and Checkboxes have a property named checked and an event name checkedchanged.

I would like to know if both are used to test if a checkbox is selected or a radio button is selected.

is there any explanation when we should use checked versus checkedchanged?


Question by:jskfan
    LVL 55

    Assisted Solution

    by:Jaime Olivares
    You are comparing apples with oranges.

    'CheckedChanged' is an event that will be fired when the check state is altered.
    ***inside*** CheckedChanged event handler function, you have to evaluate the 'Checked' property the current state of the checkbox or radio.
    LVL 4

    Assisted Solution

    Checked property return true or false which reflect the status of the Checkbox.
    bool isChecked = chkSelect.Checked;

    CheckedChanged return EventHandler. If you have no idea about EventHandler, just consider it is a function or method which is called when you check or uncheck the checkbox.
    Have a look at the code below. The code is add a function to your eventhandler when event CheckChanged is triggered. The method name is chkSelect_Clicked.
    chkSelect.CheckedChanged += new EventHandler(this.chkSelect_Clicked);

    This material may help you go in deeper detail.

    Author Comment

    if I understand
    when you check or uncheck the radio button or checkbox, there is an event fired (checkedchanged). we can trigger this event through handles from another procedure. so we don't use checkedchanged to test if the radio button or checkbox has been checked.

    it seems like the 2 following procedures will do the same thing:

    sub proc1 checkbox1_checkedchange(arguments here) handles ......
    ' calculate future value
    end sub

    sub proc2(arguments here)
    if checkbox1.checked then
    'calculate future value
    end sub

    LVL 55

    Accepted Solution

    >it seems like the 2 following procedures will do the same thing:
    >sub proc1 checkbox1_checkedchange(arguments here) handles ......
    >' calculate future value
    >end sub
    >sub proc2(arguments here)
    >if checkbox1.checked then
    >'calculate future value
    >end sub

    Not exactly, checkbox1_checkedchange() will ocur every time check value changes, no matter checked or unchecked, you have to evaluate by yourself.
    proc2() can ocur at any arbitrary time, depending on your programming, not necessarily when check state changes, so you can fire proc2() many times when checkbox is checked, checked and cheked, or unchecked, unchecked, unchecked, taking action when it is not necessary.
    So, first aproach is more ***efficient***.

    Featured Post

    Javascript: Crash Course

    Javascript is not only emerging as the most important language to know, it's flexibility is unique. With Javascript being deployed on the web, mobile and even the desktop this is the one language that all technologists need to know.

    Join & Write a Comment

    Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now