Data-binding a set of flag to a group of checkboxes

Data-binding a set of flag to a group of checkboxes

Post by Marc Scheu » Fri, 19 Aug 2005 16:05:49


Folks,

I have an object that contains a number of properties. One of those is
an INT field that represents a bitmask of flags that can be turned on
or off.

I use a Windows form to display the value of that object and the user
can edit those values. I use data binding to connect the object's
properties to UI elements on the form.

This works well for strings and ints and stuff, but I'm stumped about
how to automagically bind the INT representing a group of flags to a
group of checkboxes that I have on my form.

Is there an easy way to do this, or is this something I need to do
manually in code?

Thanks for any hints and pointers!

Marc
================================================================
Marc Scheuner May The Source Be With You!
Berne, Switzerland m.scheuner -at- inova.ch
 
 
 

Data-binding a set of flag to a group of checkboxes

Post by Bento » Wed, 24 Aug 2005 00:42:30

> I have an object that contains a number of properties. One of those is

I don't know if this helps. I use the FireBird SQL server, which in the
current version it does not have a true BOOLEAN data type. We emulate
boolean fields with char fields of size 1, and use a field constraint to
enforce that only "T" or "F" values can be entered. To databind this
"boolean" fields to CheckBoxes, which are true boolean, I derived my own
custom CheckBox object. I think the idea behind this will help you with with
your problem.

Regards,

-Benton

using System;

using System.Text;

using System.Drawing;

using System.ComponentModel;

namespace Tenerife.MyControls

{

[ToolboxBitmap(typeof(System.Windows.Forms.CheckBox))]

public class MyCheckbox : System.Windows.Forms.CheckBox

{

const string TRUE = "T";

const string FALSE = "F";

[Browsable(false),

Bindable(true)]

public string Valor

{

get

{

if (this.Checked)

return TRUE;

else

return FALSE;

}

set

{

if (value == TRUE)

this.Checked = true;

else

this.Checked = false;

}

}

}

}

------------------------
Then, to databind the "ACTIVO" field to the textbox, I use the added
property "Valor":

chkIsActive.DataBindings.Add("Valor", binProvs, "ACTIVO");

 
 
 

Data-binding a set of flag to a group of checkboxes

Post by Bento » Wed, 24 Aug 2005 00:44:32

<SNIP>

Please make that "textbox" a checkbox :-)

Regards,

-Benton