ComboBox in TabControl

G

Guest

I have 2 ComboBox in a form. One is in a TabPage of a TabControl
They are data-associated through a code as this

objDA.Fill(objDS
With objComboBo
.ValueMember = strI
.DisplayMember = strValu
.DataSource = objDS.Tables(0
.SelectedValue = 0 : .SelectedIndex = -
End Wit

When the form is shown, the one in the form contains the items but has no one selected while the one in the TabPage of the TabControl has the first item selected... If I force the empty selection setting his SelectedValue=0 or/and SelectedIndex=-1 it goes ok, but when I change the TabPage and then return to it, the first item is shown again !!
Any ideas ??
Thanks in advance..
nq
 
C

ClayB [Syncfusion]

Something to try:

Make sure both comboboxes are using the same bindingcontext. So maybe in
formload, add code like

Me.objComboBox1.BindingContext = Me.BindingContext
Me.objComboBox2.BindingContext = Me.BindingContext

This will force both controls to use the bindingcontext of the form.
Normally, a control inherits the bindingcontext from its parent. This can
cause problems for controls on tabpages if they are suppose to bind to the
same datasource as another control on the form or another tabpage.

=========================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools


Nicola said:
I have 2 ComboBox in a form. One is in a TabPage of a TabControl.
They are data-associated through a code as this:

objDA.Fill(objDS)
With objComboBox
.ValueMember = strID
.DisplayMember = strValue
.DataSource = objDS.Tables(0)
.SelectedValue = 0 : .SelectedIndex = -1
End With

When the form is shown, the one in the form contains the items but has no
one selected while the one in the TabPage of the TabControl has the first
item selected... If I force the empty selection setting his SelectedValue=0
or/and SelectedIndex=-1 it goes ok, but when I change the TabPage and then
return to it, the first item is shown again !!!
 

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