V
vaporpop
I have a checkbox (along with textboxes) that I am trying to use as a
databound control to an integer field on a database. I am using
Format and Parse with the checkbox to write -1 to the database if the
checkbox is unchecked and 0 if checked. I am finding that the Dataset
and Database are not updated if I change the checkstate of the
checkbox and when I change the checkstate of the textbox, the other
controls (textboxes) will not allow focus. The code I have written is
below. Any suggestions would be appreciated.
// chbActive
System.Windows.Forms.Binding chkBoxBinding = new
System.Windows.Forms.Binding("CheckState",
this.tblEmployeeBindingSource, "inActive", true);
chkBoxBinding.Format += new
System.Windows.Forms.ConvertEventHandler(IntegerToCheckState);
chkBoxBinding.Parse += new
System.Windows.Forms.ConvertEventHandler(CheckStateToInteger);
this.chbActive.DataBindings.Add(chkBoxBinding);
this.chbActive.CheckStateChanged += new
System.EventHandler(this.chbActive_CheckStateChanged);
//this handles integer to checkstate
private void IntegerToCheckState(object sender, ConvertEventArgs
cevent)
{
// the method converts only to CheckState inActive is 0 if false
if ((int)cevent.Value == 0)
{
chbActive.CheckState = CheckState.Checked;
}
else
{
chbActive.CheckState = CheckState.Unchecked;
}
}
private void CheckStateToInteger(object sender, ConvertEventArgs
cevent)
{
// if Active is checked then they are active and inActive should
be 0
if (chbActive.CheckState == CheckState.Checked)
{
cevent.Value = 0;
}
else
{
cevent.Value = -1;
}
}
databound control to an integer field on a database. I am using
Format and Parse with the checkbox to write -1 to the database if the
checkbox is unchecked and 0 if checked. I am finding that the Dataset
and Database are not updated if I change the checkstate of the
checkbox and when I change the checkstate of the textbox, the other
controls (textboxes) will not allow focus. The code I have written is
below. Any suggestions would be appreciated.
// chbActive
System.Windows.Forms.Binding chkBoxBinding = new
System.Windows.Forms.Binding("CheckState",
this.tblEmployeeBindingSource, "inActive", true);
chkBoxBinding.Format += new
System.Windows.Forms.ConvertEventHandler(IntegerToCheckState);
chkBoxBinding.Parse += new
System.Windows.Forms.ConvertEventHandler(CheckStateToInteger);
this.chbActive.DataBindings.Add(chkBoxBinding);
this.chbActive.CheckStateChanged += new
System.EventHandler(this.chbActive_CheckStateChanged);
//this handles integer to checkstate
private void IntegerToCheckState(object sender, ConvertEventArgs
cevent)
{
// the method converts only to CheckState inActive is 0 if false
if ((int)cevent.Value == 0)
{
chbActive.CheckState = CheckState.Checked;
}
else
{
chbActive.CheckState = CheckState.Unchecked;
}
}
private void CheckStateToInteger(object sender, ConvertEventArgs
cevent)
{
// if Active is checked then they are active and inActive should
be 0
if (chbActive.CheckState == CheckState.Checked)
{
cevent.Value = 0;
}
else
{
cevent.Value = -1;
}
}