Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to bind textbox, checkbox
Message
De
30/10/2009 12:35:09
 
 
À
29/10/2009 20:58:08
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Versions des environnements
Environment:
C# 3.0
OS:
Vista
Network:
Windows 2003 Server
Database:
MySQL
Application:
Web
Divers
Thread ID:
01432218
Message ID:
01432388
Vues:
74
This message has been marked as the solution to the initial question of the thread.
OK ... I assume this means that you are actually needing to databind to a string?

This CheckBox binds directly to your DataColumn rather than an intermediary property (which can be done too, but takes more code IMHO). This class can be extended to be able to used with other strings, such as T/F, but I’ll leave that as an exercise for the reader:
public class BBCheckBoxString : System.Windows.Forms.CheckBox
{
	protected Binding oBinding = null;

	public virtual void DataBind(System.Data.DataTable Data, string Column)
	{
		this.Checked = false;
		this.oBinding = new Binding("Checked", Data, Column);

		this.oBinding.Format += new ConvertEventHandler(this.FormatHandler);
		this.oBinding.Parse += new ConvertEventHandler(this.ParseHandler);

		this.DataBindings.Add(this.oBinding);
	}
	protected override void FormatHandler(object sender, ConvertEventArgs e)
	{
		if (e.Value.ToString() == "Y")
			e.Value = true;
		else
			e.Value = false;
	}
	protected override void ParseHandler(object sender, ConvertEventArgs e)
	{
		if ((bool)e.Value == true)
			e.Value = "Y";
		else
			e.Value = "N";
	}
}
Then, on your Form or control, to databind that Checkbox, you’d do this:
this.MyCheckBox.DataBind(MyTable, "MyYNColumn");
~~Bonnie
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform