feurich Posted November 3, 2003 Posted November 3, 2003 (edited) Hi there everyone. I'm trying to clear some contrlos created at runtime on a combobox Selectedvaluechange event but I get a strange error. could someone take a look at the code and maybe give me some info on what i'm doing wrong. This is test code i'm using, but it reacts the same in my org. code. The error occurs when clearing the controls in the clearcontrols routine. The code comes across a control that is not defined and gives the error "Object reference not set to an instance of an object" GreetZ, Feurichform1.vb Edited November 3, 2003 by feurich Quote Trust the Universe
Administrators PlausiblyDamp Posted November 3, 2003 Administrators Posted November 3, 2003 try changing the ClearControls sub to Private Sub ClearControls() '*** Clear controls But leave Combobox1 on the form. Dim i As Integer For i = Me.Controls.Count - 1 To 0 Step -1 If Me.Controls(i).Name <> "ComboBox1" Then Me.Controls(i).Dispose() End If Next End Sub Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
feurich Posted November 3, 2003 Author Posted November 3, 2003 EUREKA !!!!! It works ...i'm baffled. Could you please explain why the controls collection has to be looped backwords ??? THanks a mil. Cire Quote Trust the Universe
Administrators PlausiblyDamp Posted November 3, 2003 Administrators Posted November 3, 2003 If you are disposing of them while going forwards then I think the internal numbers are being moved down by one everytime you delete something. Starting at the top and working down prevents you skipping over them in this way. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
feurich Posted November 3, 2003 Author Posted November 3, 2003 Makes Sense That makes sense. I have read "everything" on Controls collection in the MSDN but this behaviour isn't mentioned anywhere. That's why there are these forums. GreetZ, Cire:p Quote Trust the Universe
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.