|
-
Feb 3rd, 2003, 09:07 PM
#1
Thread Starter
Frenzied Member
Confused ComboBox
This is one weird glitch. I've searched the forums and the web, and still i have not found anyone else that has encountered this.
On a WinForm, drop on 2 ComboBoxes, and then place this code in behind it:
VB Code:
Dim bFormLoading As Boolean = True
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim arText() As String = {"", "Red", "White", "Blue"}
ComboBox1.DataSource = arText
ComboBox2.DataSource = arText
'MsgBox("form_load")
bFormLoading = False
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If bFormLoading = False Then MsgBox("ComboBox1")
End Sub
Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
If bFormLoading = False Then MsgBox("ComboBox2")
End Sub
When you run the program and select something from either combo box, the code for both fires!
I think it's some kind of weird situation where .NET is re-drawing the form, and thus it is re-selecting an item in each combo box. But i'm not sure.
It's the weirdest thing i've ever seen.
~Peter

-
Feb 4th, 2003, 04:08 AM
#2
Frenzied Member
It is not related to form painting event. As obvious in your code, you have bound tow comboboxes to one datasource and when you change one combobox the underlying binding manager position changes, so it fires the other combobox.
-
Feb 4th, 2003, 10:02 AM
#3
Thread Starter
Frenzied Member
-
Feb 4th, 2003, 10:14 AM
#4
Frenzied Member
Well, am not that experienced to judge if it is a bug or not, but IMHO its not, its just the nature of binding i guess. Why dont you just populate your comboboxes with the array instead of binding to that array?
-
Feb 4th, 2003, 12:59 PM
#5
Thread Starter
Frenzied Member
You say i should populate instead of binding.... Can you give me an example of what you are thinking?
~Peter

-
Feb 4th, 2003, 01:35 PM
#6
Frenzied Member
Too easy
VB Code:
Dim arText() As String = {"", "Red", "White", "Blue"}
ComboBox1.Items.AddRange(arText)
ComboBox2.Items.AddRange(arText)
-
Feb 4th, 2003, 03:03 PM
#7
Thread Starter
Frenzied Member
-
Feb 4th, 2003, 03:22 PM
#8
Frenzied Member
You're most welcome!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|