• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 713
  • Last Modified:

Checked and Checkedchanged.

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?

thanks

0
jskfan
Asked:
jskfan
  • 2
3 Solutions
 
Jaime OlivaresCommented:
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.
0
 
nguyenvinhtuCommented:
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.
http://msdn2.microsoft.com/en-US/library/system.web.ui.webcontrols.checkbox.checkedchanged(VS.80).aspx
0
 
jskfanAuthor Commented:
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.
Correct?

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
endif
end sub

 
0
 
Jaime OlivaresCommented:
>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
>endif
>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***.
 
 
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now