Combo box BUG

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

I am encountering a problem with the combo box. This
only happens when using the datasource property, I create
a table with the following values (a, b, c, d).

Step 1. Select the "c" value from the drop down list by
typing "c" into the combo box. Then click off from the
combo to say a button. Have the button populate a text
box with the combo boxes text property.
Result = "a"
Step 2. Repeat step 1, but type in "b" this time.
Result = "c"

I believe that this is a bug in VB.net. I am trying to
find a work around for this issue and would appreciate
any suggestions.
 
Just tested this and it workds ok for me. Post your code !

Regards - OHM
 
I've tried it msyelf and can't replicate it. First, I add a, b, c , and d
to a combo box. I have a label and a button. I type in c in the combo box,
and press the button which sets the label to the combobox's Text Property.
If I select or type in c, c is what appears in the label. Same for all of
the other letters. In general though, I'd advise against using the text
property, use ..SelectedValue if you are bound to a datasource and have the
ValueMember set, otherwise use SelectedIndex.


HTH,

Bill
 
To duplicate try expanding the Dropdown, then type in "c"
then click on the button without collapsing the
dropdown. Btw, it works fine when not using a datasource.

Here is my code

'Load the combo box on form load
Private Sub Form5_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim dtTest As New DataTable()

dtTest.Columns.Add("Desc")
dtTest.Columns.Add("Code")

Dim iX As Int16

For iX = 1 To 10
Dim drRow As DataRow = dtTest.NewRow
drRow("Code") = iX
drRow("Desc") = Chr(64 + iX) & CType(iX,
String)
dtTest.Rows.Add(drRow)
Next

With ComboBoxEx1
.DataSource = dtTest
.DisplayMember = "Desc"
.ValueMember = "Code"
End With
End Sub

Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
TextBox1.Text = ComboBoxEx1.Text
TextBox2.Text = ComboBoxEx1.SelectedValue
End Sub
 
To duplicate try expanding the Dropdown, then type in "c"
then click on the button without collapsing the
dropdown. Btw, it works fine when not using a datasource.

Here is my code

'Load the combo box on form load
Private Sub Form5_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim dtTest As New DataTable()

dtTest.Columns.Add("Desc")
dtTest.Columns.Add("Code")

Dim iX As Int16

For iX = 1 To 10
Dim drRow As DataRow = dtTest.NewRow
drRow("Code") = iX
drRow("Desc") = Chr(64 + iX) & CType(iX,
String)
dtTest.Rows.Add(drRow)
Next

With ComboBoxEx1
.DataSource = dtTest
.DisplayMember = "Desc"
.ValueMember = "Code"
End With
End Sub

Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
TextBox1.Text = ComboBoxEx1.Text
TextBox2.Text = ComboBoxEx1.SelectedValue
End Sub
 
Ok, I see what you mean now. You aren't selecting anything so the
SelectedItem and value are what they originally are, and although the text
has changed, the SelectedIndex changed never fires hence it's the old value.
Write some code behind selectedIndexChanged and you'll see what I mean just
put in Debug.Assert(false) When you follow your instructions, you'll notice
that the assertion never fails because the event isn't being raised.
However, if you click anywhere on there, it does.

Anyway, once selectedindex change is fired, it's good to go, so rather than
a bug it just seems like that sequence doesn't fire the event
 
Hi Mark,

Now I could reproduce it, I think I did not understand you.

I changed some code, I thought the error would be bigger, strange enough
with me the error was gone, maybe you can use it.
\\\
Private Sub Form5_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim dtTest As New DataTable
dtTest.Columns.Add("Desc")
dtTest.Columns.Add("Code")
Dim iX As Integer
For iX = 1 To 10
Dim drRow As DataRow = dtTest.NewRow
drRow("Code") = iX
drRow("Desc") = Chr(64 + iX) & CType(iX, String)
dtTest.Rows.Add(drRow)
Next
With ComboBox1
.DataSource = dtTest
.DisplayMember = "Desc"
.ValueMember = "Code"
End With
TextBox1.DataBindings.Add(New Binding("Text", dtTest, "Desc"))
TextBox2.DataBindings.Add(New Binding("Text", dtTest, "Code"))
End Sub
///

Cor
 
Back
Top