Question Boolean formatting

rickydalley

Member
Joined
Aug 28, 2009
Messages
24
Programming Experience
10+
I'd like to be able to specify something other than true/false when dealing with booleans.

At times I'd like to get it to show yes/no or on/off or even y/n

I've searched the internet and alas I haven't seen anything.

has anyone here dealt with this before?

regards, Ricky

P.S this is in regards to setting the format of a datagridcolumn that holds a boolean field
 
I've done this before where they want a Yes/No shown on the report instead of True/False:
VB.NET:
Dim SomeBoolean As Boolean
SomeBoolean.ToString.Replace("True", "Yes").Replace("False", "No")
For it to be On/Off simply replace the True part with On and the False part with Off.

I don't know to do this with a DataGridColumn though.
 
thanks but not quite what i needed

What I wanted is for when I display a datagrid that has a boolean field that it would show something other than True or False

this case statement in the sql select is what does the trick

Thanks to inertiam who showed me the case statement.

here's the sql string:

VB.NET:
Select FareId,FareDate,FareHash,TimeStart,TimeEnd,Pickup,Dropoff,Fare,FareType, CASE(Booked) WHEN 1 THEN 'Yes' WHEN 0 THEN 'No' END As Booked From Fares Order By FareDate Desc, FareHash Desc

the boolean is stored in my sqlce db as a bit - 0 or 1. 0 is false, 1 is true.
Because the value can only be 0 or 1 I don't need an ELSE in the CASE section.

So when I fill a temporary table with this sql I get Yes or No for the Booked column.

on my edit form the boolean is represented as a checkbox and I just need this

VB.NET:
chkBooked.Checked = IIf(.Item("Booked") = "Yes", True, False)

so a Yes on the grid will show a tick in the checkbox on the edit form or if the grid is showing a No it is unticked.

Works perfectly.

regards, Ricky

P.S you can look at the discussion I have with inertiam in the Components section to see how it evolved.
 
I use a bit field in Sql Server for my boolean values (0 false, 1 true). In my typed datasets I set the datatype for this field as boolean. Attached to a DataGridView control, it shows a checkbox for the column fields. Checked is true, Unchecked is false.
 
is that for desktop?

I ask because we don't have a DataGridView control in .Net CF

We have a DataGrid control.

Also I'm not using datasets in my code - I populate a grid via a bindingsource using a command object and in some places a datareader (for populating my autocomplete combo boxes). I also use a command object to write data back to the db

I find this takes less memory which on a pda is important.

regards, Ricky
 
Back
Top