Using VS 2005 beta 2. I did a drag and drop of a data source table that points to an existing SQL Server 2000 table. I want to use a chekbox with a few fields. They are defined as smallint and have nulls, 0, and 1 in the exisitng data.
The chekboxs show up OK on the form in IDE but at runtime they do not track the data values. If I add a teckbox instead the data displays OK.
When I click on any of the checkboxs in run mode the program hangs. I need to switch to the IDE to stop the program.
1) Is this a know bug
2) Or am I trying something that can't be done I haven't been able to find any docs stating the requirements for the data under the CheckBox.
3) What is the best way to proceed to support my existing data using a checkbox
TIA

VS 2005 CheckBox bound to SQL Server 2000
Chris Powell
I'm using VB. I can barely decode what you wrote. I have no clue where the code would go in a Windows Form bound to a datasource.
Please translate
Fendy
Joe
fcsobel
Seems to. I can open the table in Access, delete the 1 or 0 that is there, and Null shows in Server Explorer. Back in VS form the checkbox shows as unchecked for that record when Null. I can check it and a 1 shows up in the record. Uncheck and 0 shows up.
The table design probably shouldn't allow nulls but...
Phil
Joe
MathiasWestin
I swaped the DataBinding values of CheckState and Checked on the CheckBox that was created by dragging a DataSource Tables(Details) on to a form. That is the two properties were bound incorrectly. Now CheckState is set to None and Checked is points to the proper field.
Seems to work OK with 1, 0, and Null SmallInt from SQL Server 2000.
Thanks!
GlennG
OK - that makes sense. What I was tryint to ask was if the CheckBox was showing its tri-state mode for DBNull.Value and it's not (which it shouldn't). If you bind to CheckState using Format/Parse events as described above, then it will work correctly in tri-state as well.
Note that post B2, we'll fix this such that binding an int (or SmallInt) to CheckedState will work correctly.
Joe
Guino
CheckBox data binding works with nullable SQL columns of type bool however you'll need to write some code to get this to work with other column types. For a small int column type, you need to write format and parse events for the Binding. I've included a sample below.
Joe
Binding b = new Binding("CheckState", dataSource, "SmallIntColumn", true, DataSourceUpdateMode.OnPropertyChanged);
b.Format += delegate(object fs, ConvertEventArgs fa)
{
if (fa.Value is Int16)
{
Int16 value = (Int16)fa.Value;
fa.Value = ((value == 0) CheckState.Unchecked : CheckState.Checked);
}
else
{
fa.Value = CheckState.Indeterminate;
}
};
b.Parse += delegate(object ps, ConvertEventArgs pa)
{
CheckBox cb = ((ps as Binding).Control as CheckBox);
if (cb.CheckState == CheckState.Checked)
{
pa.Value = 1;
}
else if (cb.CheckState == CheckState.Unchecked)
{
pa.Value = 0;
}
else
{
pa.Value = DBNull.Value;
}
};
this.checkBox1.DataBindings.Add(b);