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

Combobox strange behavior

P: n/a
I have a form with two cboboxes with the DropDownStyle set to DropDown.
When the form loads, it fills cboCategory1 with data. When the text of
cboCategory1 changes (when an item in the list is selected or a new entry is
made), cboCategory2 is supposed to fill with relevant categories:

\\\
Private Sub cboCategory1_TextChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cboCategory1.TextChanged
Dim a As Integer
MsgBox("")
cboCategory2.Items.Clear()
For a = 0 To Category2.GetUpperBound(0) 'Category2 is a DataRow with
columns "Category1" and "Category2"
If Category2(a)("Category1").ToString = cboCategory1.SelectedText Then
If Not cboCategory2.Items.Contains(Category2(a)("Category 2").ToString)
Then
cboCategory2.Items.Add(Category2(a)("Category2").T oString)
End If
End If
Next
End Sub
\\\

Now you're first question is going to be, what's the purpose of MsgBox("")?
I put that in at first to test whether the .TextChanged event was being
called properly. The strange thing is, the code as it is above works, but
if I take MsgBox("") out, it doesn't. I tried taking it out, closing VS,
restarting the computer and reloading the solution. It still didn't work
unless I put the MsgBox("") back in. What is happening?
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Have you tried putting this code in a different event such as
SelectedIndexChanged?
Nathan wrote:
I have a form with two cboboxes with the DropDownStyle set to DropDown.
When the form loads, it fills cboCategory1 with data. When the text of
cboCategory1 changes (when an item in the list is selected or a new entry is
made), cboCategory2 is supposed to fill with relevant categories:

\\\
Private Sub cboCategory1_TextChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cboCategory1.TextChanged
Dim a As Integer
MsgBox("")
cboCategory2.Items.Clear()
For a = 0 To Category2.GetUpperBound(0) 'Category2 is a DataRow with
columns "Category1" and "Category2"
If Category2(a)("Category1").ToString = cboCategory1.SelectedText Then
If Not cboCategory2.Items.Contains(Category2(a)("Category 2").ToString)
Then
cboCategory2.Items.Add(Category2(a)("Category2").T oString)
End If
End If
Next
End Sub
\\\

Now you're first question is going to be, what's the purpose of MsgBox("")?
I put that in at first to test whether the .TextChanged event was being
called properly. The strange thing is, the code as it is above works, but
if I take MsgBox("") out, it doesn't. I tried taking it out, closing VS,
restarting the computer and reloading the solution. It still didn't work
unless I put the MsgBox("") back in. What is happening?

Nov 20 '05 #2

P: n/a
Yes, and I get the same result. But I do need it in the TextChanged event.

"copyco" <co****@anon.com> wrote in message
news:jX******************@newssvr23.news.prodigy.c om...
Have you tried putting this code in a different event such as
SelectedIndexChanged?
Nathan wrote:
I have a form with two cboboxes with the DropDownStyle set to DropDown.
When the form loads, it fills cboCategory1 with data. When the text of
cboCategory1 changes (when an item in the list is selected or a new entry is made), cboCategory2 is supposed to fill with relevant categories:

\\\
Private Sub cboCategory1_TextChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cboCategory1.TextChanged
Dim a As Integer
MsgBox("")
cboCategory2.Items.Clear()
For a = 0 To Category2.GetUpperBound(0) 'Category2 is a DataRow with columns "Category1" and "Category2"
If Category2(a)("Category1").ToString = cboCategory1.SelectedText Then If Not cboCategory2.Items.Contains(Category2(a)("Category 2").ToString) Then
cboCategory2.Items.Add(Category2(a)("Category2").T oString)
End If
End If
Next
End Sub
\\\

Now you're first question is going to be, what's the purpose of MsgBox("")? I put that in at first to test whether the .TextChanged event was being
called properly. The strange thing is, the code as it is above works, but if I take MsgBox("") out, it doesn't. I tried taking it out, closing VS, restarting the computer and reloading the solution. It still didn't work unless I put the MsgBox("") back in. What is happening?

Nov 20 '05 #3

P: n/a
Yes, I did try that, and I get the same error :( However, I need it to be
in the textchanged event
"copyco" <co****@anon.com> wrote in message
news:jX******************@newssvr23.news.prodigy.c om...
Have you tried putting this code in a different event such as
SelectedIndexChanged?

Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.