Combobox showing first item??

N

Nate

I have used the feedback on this issue to remedy my comboboxes showing
the first item on the list when a new record is added to the binding
context ---
Me.BindingContext(dsOrders, "tblOrders").AddNew()
Me.ComboBox1.SelectedIndex = -1

but... how do we deal with the same issue during record navigation?
When I move forward or backward onto a null field the combo defaults to
the first item on the list again?

Me.BindingContext(dsOrders, "tblOrders").Position =
(Me.BindingContext(dsOrders, "tblOrders").Position + 1)

I am convinced that anyone using combos is having this problem...

I am binding early, clearing and rebinding late, trying many variations
to no avail. I have added an empty string value to the first item of
all my combos - this displays an empty box for null fields, but is not
optimal. Anybody have a workaround for this??
 
B

Bart Mermuys

Hi,

Nate said:
I have used the feedback on this issue to remedy my comboboxes showing
the first item on the list when a new record is added to the binding
context ---
Me.BindingContext(dsOrders, "tblOrders").AddNew()
Me.ComboBox1.SelectedIndex = -1

but... how do we deal with the same issue during record navigation?
When I move forward or backward onto a null field the combo defaults to
the first item on the list again?

I recently posted a workaround for what i can only guess deals with your
problem. Are you talking about lookup ComboBox's to which you have added a
binding for SelectedValue ?,eg.:

Me.ComboBox1.Bindings.Add( "SelectedValue", dsOrders,
"tblOrders.SomeFkField" )

If so, then yes there is a problem with null values, and here is a
workaround:

AddHandler Me.BindingContext(dsOrders, "tblOrders").PositionChanged, _
AddressOf CmPositionChanged

Private Sub CmPositionChanged( ByVal sender As Object, ByVal e As
System.EventArgs)
'
Dim cm As CurrencyManager = _
DirectCast(sender, CurrencyManager)
Dim lv As DataRowView = _
DirectCast(cm.Current, DataRowView)
Dim cb As ComboBox

For Each bnd As Binding In cm.Bindings
If (bnd.PropertyName = "SelectedValue") And _
(TypeOf (bnd.Control) Is ComboBox) Then
cb = DirectCast(bnd.Control, ComboBox)
If (lv(bnd.BindingMemberInfo.BindingField) Is DBNull.Value) And _
(cb.SelectedIndex <> -1) Then
cb.SelectedIndex = -1
End If
End If
Next
End Sub


HTH,
Greetings
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top