Check Box Binding

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am having trouble with the binding of a check box. I have a form for
editing and adding reps. I am using a bindingsource and a bindingnavigator.
I have on the form an "Active" checkbox, which is bound to the IsActive field
in the bound data table. It works fine for the reps that are already in the
table. The problem occurs when I click on the AddNew button on the
bindingnavigator. I have the field in the table to default to true, because
when I add a rep, he will be active. The checkbox is checked when the AddNew
is clicked, but that data is never written back to my underlying data.
Everything else is written, but the IsActive field is false, despite what is
in the check box. How can I get the new rep to have the IsActive field set
to true?
 
Vernon,

What type of the DataSource? Dataset or customer object: Have you checked the underlying data after
it is created to make sure Active is set true?

How do you know it's the binding and not the routine to write it back? Have you checked the
underlying data just before it is written back to the DB?

Flomo
 
The underlying database is an Access database. I have checked and it is not
set True.

The only routine to write the data back is:

Me.RepsBindingSource.EndEdit()
Me.RepsTableAdapter.Update(dt)
dt.AcceptChanges()

The rest of the data is written back, so I don't understand why the Active
field isn't.
 
Vernon,

Place this line between the EndEdit and Update methods:

Dim row As dsReps.RepsRow = DirectCast(DirectCast(RepsBindingSource.Current, DataRowView).Row,
dsReps.RepsRow)

The variable row represents a row in the dataset. I'm not sure of the dataset name and table row
name, but substitute the proper variable names. Then in debug, set a breakpoint and look at the
value of Active. Is it what you expect?

You could also use QuickWatch in debug if your familiar with walking the data structure.
 
The only thing that this tells me is that all of the values in the table
currently are null.
 
Vernon,

Sorry about that. There is probably no current row then. Place that code in the CheckedChanged
event of the checkbox and look at the Active column, row.Active.


--
 
row.Active didn't exist, and everything I tried to look at still was null.
However, I figured out a workaround to take care of my problem. My code is:

Me.RepsBindingSource.MoveFirst()
For i As Integer = 0 To Me.RepsBindingSource.Count - 1
Dim drv As DataRowView = Me.RepsBindingSource.Current
Dim row As DataRow = drv.Row
If row.RowState = DataRowState.Added Then
row.Item("IsActive") = True
End If
Me.RepsBindingSource.MoveNext()
Next
Me.RepsBindingSource.EndEdit()
Me.RepsTableAdapter.Update(dt)

If I step through this code, the value of row.Item("IsActive") is DBNull
before the statement assigning its value. Yet this box is bound to the
database. I still don't understand why it won't work. I think that we might
have a bug, but what I have done works.
 
Back
Top