Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Checkboxes on non-boolean data types
Message
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
00878298
Message ID:
00878486
Views:
17
Hi Clay,

You can use the Format and Parse methods to convert the character to the boolean value needed for binding. Look at Message #670154 for information about how to do this.

I also found this sub-class of the checkbox that allows for Y/N T/F and binds it correctly. I have not used it but wanted to pass it along:
using System;
using System.Windows.Forms;
using System.Data;

namespace System.Windows.Forms
{
public enum BoolText
{
YN = 0,
TF
}

/// <summary>
/// Summary description for BoolCharCheckBox.
/// </summary>

public class BoolCharCheckBox : CheckBox
{
private BoolText boolTextType;

public virtual void BindData(string propertyName, object dataSource, string
dataMember, BoolText boolTextType)
{
this.boolTextType = boolTextType;
Binding db = new Binding(propertyName, dataSource, dataMember);
db.Format += new ConvertEventHandler(this.FormatHandler);
db.Parse += new ConvertEventHandler(this.ParseHandler);
this.DataBindings.Add(db);
}

private void FormatHandler(object sender, ConvertEventArgs e)
{
switch (boolTextType)
{
case BoolText.YN:
if ((string)e.Value == "Y")
e.Value = true;
else
e.Value = false;
break;
case BoolText.TF:
if ((string)e.Value == "T")
e.Value = true;
else
e.Value = false;
break;
} 
}

private void ParseHandler(object sender, ConvertEventArgs e)
{
switch (boolTextType)
{
case BoolText.YN:
if ((bool)e.Value == true)
e.Value = "Y";
else
e.Value = "N";
break;
case BoolText.TF:
if ((bool)e.Value == true)
e.Value = "T";
else
e.Value = "F";
break;
} 
} 

} 
}
>Ok next problem. :)
>
>What is the best way to bind a checkbox to a CHAR(1) data type containing an 'N' Or 'Y'?
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Reply
Map
View

Click here to load this message in the networking platform