Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / General / October 2004

Tip: Looking for answers? Try searching our database.

Q: Converting CheckBox.Checked to an int?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Visual Systems AB \(Martin Arvidsson\) - 26 Oct 2004 21:38 GMT
Hi!

How do I convert a CheckBox.Checked to an int?

Regards

Martin Arvidsson
Morten Wennevik - 26 Oct 2004 21:51 GMT
Hi Martin,

To get an int value out of you can do something like

int i = CheckBox.Checked ? 1 : 0;

A boolean value can't be translated to any other value, so you will need  
to test it, if true use 1, otherwise use 0.

Signature

Happy Coding!
Morten Wennevik [C# MVP]

Scott M. - 26 Oct 2004 22:25 GMT
No, you shouldn't have to test it.  You should be able to cast it into an
integer and get back 0 or 1 directly.

> Hi Martin,
>
[quoted text clipped - 4 lines]
> A boolean value can't be translated to any other value, so you will need
> to test it, if true use 1, otherwise use 0.
Morten Wennevik - 27 Oct 2004 06:20 GMT
> No, you shouldn't have to test it.  You should be able to cast it into an
> integer and get back 0 or 1 directly.

To add to this, there is no CType in C#, but you get the same effect using
Convert.ToInt32(bool)

Signature

Happy Coding!
Morten Wennevik [C# MVP]

Scott M. - 26 Oct 2004 21:51 GMT
VB.NET:

CType(checkbox.checked, Integer)

"Visual Systems AB (Martin Arvidsson)" <martin.arvidsson@vsab.net> wrote in
message news:%23ycwLv5uEHA.1452@TK2MSFTNGP11.phx.gbl...
> Hi!
>
[quoted text clipped - 3 lines]
>
> Martin Arvidsson

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.