Weird combo control occurences
I'm having some very weird problems with combo controls that i'm using on my form and wanted to see if anyone ever had any similiar incidents.
I have it set to load some data when you select an item in the combobox. Well it loads the data fine but then for some odd reason it sets the combobox = "".
Now I've checked and it dosn't do it anywhere in the load function.. nor anywhere lol..
I added the control to a watch and told it to break on changes (comboName.Text was the expression I used) and it breaks when I clear the form to ensure a clean form before loading data, and breaks again when I set the text in it back to the item I'm loading, then it never breaks again yet the text in it changes to nothing....
I dont get it even the watch isn't picking it up as changing but it is in fact changing.
Re: Weird combo control occurences
i think we will need to see your code when you add the data and upto the point when it clears.
casey.
Re: Weird combo control occurences
Well that could be a problem because I dont know the point where it clears. It does not occur in code anywhere.. I'd have to upload my entire project and I dont really consider that an option right now.
Re: Weird combo control occurences
Best you can do Steven is to step though your code - it may take awhile but if you are aptient enough then you'll spot it.
Good luck.
Re: Weird combo control occurences
Belive it or not I tried that... I stepped through and the text in the combo clears after all code has completed. As of the last line of code that gets executed "End If", if I look back at the form while it's broken the text is still in the combo box.. as soon as I resume and no other code is being executed it clears.
It is very very bizarre, never seen anything like it and can't explain it one bit...
Re: Weird combo control occurences
There are no miracles in programming - your app does exactly what you tell it to do so debug it more thouroughly - F8 all the way ...
Re: Weird combo control occurences
I dont doubt there are no miracles in programming, but I do doubt that it is in my code. I have F8ed the entire process. This is the sub that starts the code going...
VB Code:
Private Sub cmbClass_Click()
If cmbClass.ListIndex <> -1 And Not ClassLoading Then LoadClass cmbClass.ItemData(cmbClass.ListIndex)
End Sub
As of pressing F8 and landing on End Sub the text is in the combo box. I press F8 again, no other code is executed and the text disappears.
I'm wondering if I stumbled upon some deeply routed bug with the combo box control itself.
Re: Weird combo control occurences
Quote:
Originally Posted by StevenHickerson
... I'm wondering if I stumbled upon some deeply routed bug with the combo box control itself.
I'm afraid not.
What does LoadClass do? Can you post it?
Re: Weird combo control occurences
What is the scope of your Watch statement? Is it (All procedures) and (All modules)? If so have you included the form name?
Re: Weird combo control occurences
Yes I tried watching frmMain.cmbClass.Text in all procedures / all modules. It shows in my watch window, the last watch of it with a value in the field not "".
And I can post my LoadClass code, but I can gurantee you wont find the problem there. I'm telling you stepping through the entire code the text is not cleared after the load class code has completed. It is not until after End Sub is it cleared, and stepping dosn't stop on another line unless I click another button or something on my form.
Re: Weird combo control occurences
Do you have any code for any control GotFocus/LostFocus that may have Combo1.Clear or something? These event won't fire while in debug so when form finally recieves focus it activates one of the controls and that could be crucial. So I suggest that you do search for your combobox name throughout the project and specifically for Clear method.
Re: Weird combo control occurences
Ok I finally tracked down the problem causer.. but it's still very peculiar....
this sub
VB Code:
Private Sub ClearHandle(FrameName As String)
On Error Resume Next
Dim Con As Control
For Each Con In frmMain.Controls
If Con.Container.Name = FrameName Or Con.Container.Container.Name = FrameName Then
If Con.Name = "cmbClass" Or Con.Name = "cmbStudentName" Then
Con.SetFocus
End If
If TypeOf Con Is TextBox Then
Con.Text = ""
ElseIf TypeOf Con Is ComboBox Then
If Con.Style <> 2 Then Con.Text = ""
ElseIf TypeOf Con Is ImageCombo Then
Con.Text = ""
ElseIf TypeOf Con Is ListView Then
If Con.Name <> "listBelts" Then Con.ListItems.Clear
ElseIf TypeOf Con Is CheckBox Then
Con.Value = vbUnchecked
ElseIf TypeOf Con Is ListBox Then
For i = 0 To Con.ListCount - 1
Con.Selected(i) = False
Next
End If
End If
Next
If FrameName = "ClassFrame" Then
With listClassStudents.ColumnHeaders
.Clear
.Add , , "Index", 1
.Add , , "Name"
.Add , , "Belt"
.Add , , "Tabs"
.Add , , "Age"
.Add , , "Contact"
End With
End If
End Sub
The problem code: If Con.Style <> 2 Then Con.Text = ""
Now what I don't understand is how it's getting executed. I do run this sub in the LoadClass to ensure a clean form when loading, forgot about it earlier, I tried putting break points in it at the beginning and end so I knew when it ran, as expected after it ran the text was removed from the combobox. But then the code shifted back to the LoadClass where it had been called from and I reset the text to the class being loaded.
The sub never runs again after this point but the text gets cleared later after execution of all code has completed. I know this sub dosn't run again because my breakpoints don't stop the program again, yet if I comment out that line the problem does not occur..
So now I'm baffled as to how it's executing without breaking at my break points...
I can put in a workaround now I'm sure, but I think I need to figure out where the problem is so that I can learn something and not make the mistake again.
Re: Weird combo control occurences
After going through your code one more time here's what I found and it's something that I suggested in my previous reply: the SetFocus
VB Code:
If Con.Name = "cmbClass" Or Con.Name = "cmbStudentName" Then
[b]Con.SetFocus[/b]
End If
'...
ElseIf TypeOf Con Is ComboBox Then
If Con.Style <> 2 Then Con.Text = ""
SetFocus won't get fired while in debug mode and I did mentioned that before - that's what got you confused ...
Re: Weird combo control occurences
Yeah but the setfocus isn't causing any problems there. It's not what is causing the cmbClass.Text to clear. There is no code in the GotFocus element of the cmbClass, the only purpose it serves it to put the cursor in the combobox.
Ok quick question... does setting the text of a combobox initiate the Click event? If so I think I figured out the problem although I still don't understand why it jumped my breakpoints if this is what caused it.
Re: Weird combo control occurences
I'm afraid you're missing the point: some controls cannot get cleared until they actually recieve focus. Since you're in debug control cannot get focus so you may see some value in it until it gets activated. Just like Get/LostFocus events you cannot debug MouseDown/Up (and some other) event handlers from elsewhere ...
Setting Text doesn't trigger Click event - setting ListIndex does.