By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,977 Members | 1,369 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,977 IT Pros & Developers. It's quick & easy.

Combobox showing first item??

P: n/a
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??

Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
ng
I prefer an unbound combobox.

Tom

Nate wrote:
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??

Nov 21 '05 #2

P: n/a
Hi,

"Nate" <na***************@hitchcock.org> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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

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??

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.