Hi,

I'm having a bit of a problem getting a particular type of form layout
to work as I wish. Please bear with me as this isn't going to be a
short post.

The basic idea is for a form to view/edit a single table. The layout
that I'm after is for a datagridview in a panel at the top of the form
showing the 'headline' fields. The bottom of the form (in another
panel) contains controls to show *all* of the fields for each record.
The columns are a mixture of straight text (so a textbox in the bottom
detail section), booleans (check boxes), dates (datetimepickers), and
text from a list (combos).

It almost works perfectly, but there are a couple of glitches.

What I'm doing is this...

When loading the form, I'm grabbing the dataset from SQL, setting up a
dataview based on that, setting the dataview as the datasource for the
datagridview, setting up another dataview (that will always be a
single record) that will be the source for all the bottom panel
controls and then setting the bindings for the controls in the bottom
panel.

To clarify the last two parts of that I have...

Private Sub DG_SelectionChanged(ByVal sender As Object, ByVal e As
System.EventArgs)
Try
SetDetails(Me.DG.Item(0, _
Me.DG.CurrentCell.RowIndex).Value)
Me.DG.Rows(Me.DG. _
CurrentCell.RowIndex).Selected = True
Catch ex As Exceptio
End Try
End Sub

Try Catch required just to avoid it going bang when initialising.

Private Sub SetDetails(ByVal id As Integer)
DetailRow.RowFilter = "ID=" + id.ToString
End Sub

The bindings are set while the form is loading with this (indents
removed to try to avoid word wrapping):

Private Sub SetBindings()
bm = CType(BindingContext(DetailRow), CurrencyManager)
Dim ctl As Control, cboctl As ComboBox, dtpctl As DateTimePicker
Dim chkctl As CheckBox
Dim typ As String
For Each ctl In Me.pnBottom.Controls
typ = ctl.GetType.Name
If typ <> "Label" Then
ctl.DataBindings.Clear()
Select Case ctl.Name.Substring(0, 3)
Case "cbo"
cboctl = ctl
AddHandler cboctl.SelectedValueChanged, AddressOf UpdateDG
ctl.DataBindings.Add(New Binding("SelectedValue", DetailRow, _
ctl.Name.Substring(3)))
Case "dtp"
dtpctl = ctl
AddHandler dtpctl.ValueChanged, AddressOf UpdateDG
ctl.DataBindings.Add(New Binding("Text", DetailRow, _
ctl.Name.Substring(3)))
Case "chk"
chkctl = ctl
AddHandler chkctl.CheckedChanged, AddressOf UpdateDG
ctl.DataBindings.Add(New Binding("Checked", DetailRow, _
ctl.Name.Substring(3)))
Case Else
AddHandler ctl.Leave, AddressOf UpdateDG
ctl.DataBindings.Add(New Binding("Text", DetailRow, _
ctl.Name.Substring(3)))
End Select
End If
Next
End Sub

Basic idea of that is that it grabs each control name that I want to
bind, determines the type by the first three letters of the control
name, and then binds to the relevent field name (so I have, for
example, a control called dtpTradeDate that binds to a field called
TradeDate).

The UpdateDG routine is designed to push the data back from the
controls into the datagridview. That looks something like this...

Private Sub UpdateFXSpotDG(ByVal sender As Object, _
ByVal e As System.EventArgs)
Me.bm.EndCurrentEdit()
End Sub

And that, as I say, almost works. The problem that I'm running into
is that not all of the controls update the datagridview correctly.
Textbox updates are fine, but check boxes, combos and datetimepickers
are a flaky. For example, if you click a checkbox in the detail
section then the datagridview doesn't update. If you then click the
checkbox a couple more times, it starts behaving itself. Similar
things happen with datetimepickers and combos - combos especially
where the style is set to DropDownList and you update it by tabbing to
it and using the keyboard.

I've tried using different events, but with no joy so far.

Hopefully that makes sense. Any ideas out there?