473,394 Members | 1,971 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to use Y/N values with winforms checkbox

GG
Is there a way to use Y/N values instead of true/false values?

Thanks

*** Sent via Developersdex http://www.developersdex.com ***
Oct 9 '07 #1
7 4808
Sure, but be warned, it's complicated... :)

myCheck.Checked = (IsInterested.equals("yes")) ? true : false;

Then, on the CheckChanged Event:
IsInterested = (myCheck.Checked) ? "yes" : "no";

--
Chris Mullins
<GGwrote in message news:Oo**************@TK2MSFTNGP03.phx.gbl...
Is there a way to use Y/N values instead of true/false values?

Thanks

Oct 9 '07 #2
I'm assuming you want to do this in a data grid? Is the underlying data
source a DataTable? If it is then I would create a column on the DataTable
which has an Expression property set to:

iif(%column%, 'Y', 'N')

Then, bind to that column.

You could also create a new DataGridViewTextBoxColumn which writes the
appropriate text, but that seems like way too much work.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<GGwrote in message news:Oo**************@TK2MSFTNGP03.phx.gbl...
Is there a way to use Y/N values instead of true/false values?

Thanks

*** Sent via Developersdex http://www.developersdex.com ***

Oct 9 '07 #3
If the underlying data isn't a datatable one could use a TypeConverter
and the TypeConverterAttribute to good effect.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

Nicholas Paldino [.NET/C# MVP] wrote:
I'm assuming you want to do this in a data grid? Is the underlying data
source a DataTable? If it is then I would create a column on the DataTable
which has an Expression property set to:

iif(%column%, 'Y', 'N')

Then, bind to that column.

You could also create a new DataGridViewTextBoxColumn which writes the
appropriate text, but that seems like way too much work.

Oct 9 '07 #4
"Chris Mullins [MVP - C#]" <cm******@yahoo.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Sure, but be warned, it's complicated... :)

myCheck.Checked = (IsInterested.equals("yes")) ? true : false;
myCheck.Checked = IsInterested.equals("yes");

Sorry, just a pet peeve of the "if (x) y=true; else; y=false;" variant
(instead of just "y=x").

Hilton
Oct 9 '07 #5
Well, if we're going to pick nits related to pet peeves, the comparision
should really be right:

myCheck.Checked = IsInterested.Equals("yes",
StringComparison.OrginalIgnoreCase);

Ya never know when some dev down the line will use "Yes" instead of "yes".
(I know, this is a strange pet peeve, but....)

We could keep going, and be really silly...

public Struct YesNo
{
private bool _yesOrNo;
...
public bool IsYes{ get { ... } set {...}}
public bool IsNo{ get { ... } set{...}}
}

--
Chris Mullins

"Hilton" <no****@nospam.comwrote in message
news:1j*****************@newssvr11.news.prodigy.ne t...
"Chris Mullins [MVP - C#]" <cm******@yahoo.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>Sure, but be warned, it's complicated... :)

myCheck.Checked = (IsInterested.equals("yes")) ? true : false;

myCheck.Checked = IsInterested.equals("yes");

Sorry, just a pet peeve of the "if (x) y=true; else; y=false;" variant
(instead of just "y=x").

Hilton


Oct 9 '07 #6
Chris wrote:
Well, if we're going to pick nits related to pet peeves, the comparision
should really be right:

myCheck.Checked = IsInterested.Equals("yes",
StringComparison.OrginalIgnoreCase);

Ya never know when some dev down the line will use "Yes" instead of "yes".
(I know, this is a strange pet peeve, but....)
I totally agree with you. I use string.Compare (x, y, true) since CF 1.1
does not have the method you used. I wonder which is faster on .NET
(non-CF).

Hilton
Oct 10 '07 #7
Here is a derived class that includes properties for setting valid yes/no
values and setting/getting the checked text.

public class CheckboxEx: CheckBox
{
private string _YesValue = "Y";
private string _NoValue = "N";

public string YesValue
{
get { return _YesValue; }
set
{
_YesValue = value;
}
}

public string NoValue
{
get { return _NoValue; }
set
{
_NoValue = value;
}
}

public string CheckedText
{
get
{
return this.Checked ? _YesValue: _NoValue ;
}
set
{
this.Checked = string.Compare(value,_YesValue,true)==0;
}
}
}

Kind Regards,
Mark Dykun, VP Mobile and Integration services, Castle CRM

<GGwrote in message news:Oo**************@TK2MSFTNGP03.phx.gbl...
Is there a way to use Y/N values instead of true/false values?

Thanks

*** Sent via Developersdex http://www.developersdex.com ***

Oct 17 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Angelos | last post by:
I have this list of logs stored in a MySQL DB. I display them in a list and next to each log I have a del view LINK I want to add Checkboxes next to each log and keep del and view links as...
2
by: PeterZ | last post by:
Hi, In the past I've successfully databound a conventional Winforms checkbox to a number column in an Oracle table, where 1 represents true and 0 represents false. The checkbox would be ticked...
4
by: schmidtmic | last post by:
I have a table that contains 20 checkbox fields. Each checkbox corrisponds to an Score amount. For Example: Checkbox1 is worth 10 points Checkbox2 is worth 5 points Checkbox3 is worth 2...
1
by: | last post by:
Hi, 1st, I did a search and could not find any info on this, the Google results were good, but I'm still have issues...So any help will be great. I have a frame page, which contains 3 frames...
10
by: Girish | last post by:
Hi Everyone, I am passing a form to a php script for further processing. I am able to retrieve the last value set for that given form variable using $variable=$_REQUEST;
9
by: =?Utf-8?B?UGV0ZXJX?= | last post by:
I have a TabControl on a Windows form in which I have various tab pages each with a DataGridView, the first column of which is a DataGridViewCheckBoxColumn and subsequent columns being...
0
by: cyberdawg999 | last post by:
Greetings all in ASP land I have overcome one obstacle that took me 2 weeks to overcome and I did it!!!!! I am so elated!! thank you to all who invested their time and energy towards helping me...
10
by: LionsDome | last post by:
Hello, I have a vb.net page which a bunch of checkboxes. A user can select a checkbox(s) and hit the submit button to store those values in a SQL Server table. This works fine with no problem...
9
by: raamay | last post by:
I have six checkboxes as shown below: <table> <tr> <td><input name="spec1" type="checkbox" value="0" tabindex="11" /><label id="label">Bridge Construction</label></td> </tr> <tr> <td><input...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.