?
Solved

Simple checkBox question

Posted on 2004-04-28
2
Medium Priority
?
235 Views
Last Modified: 2010-04-15
I have the following checkBox I am trying to display on my form but it show unchecked even though the data shows checked.

checkBox1.Text=datareader["Active"].ToString();

Any idea hoew to get it to properly display?

Jim
0
Comment
Question by:Jimbo456
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 21

Accepted Solution

by:
tovvenki earned 1000 total points
ID: 10945852
Hi,
If the datareader["Active"] is a bit or boolean then assign it straight to the Checked property of the checkbox and not to the text property.
 or if the datareader returns a string like Checked then
checkBox1.Text=datareader["Active"].ToString();
if (checkBox1.Text == "Checked")
      checkBox1.Checked = true;
else
      checkBox1.Checked = false;


Regards,
Venki
0
 
LVL 1

Expert Comment

by:warmach
ID: 10948564
You should not be setting the Text property at all.  This property is used as a label to the check box.  Link Venki said, you need to set the Checked property directly.  I would set the Text property to something more descriptive because it is something that the user will see.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

741 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