Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (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,

 

Feurich

form1.vb

Edited by feurich
Trust the Universe
  • Administrators
Posted

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

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

EUREKA !!!!!

 

It works ...i'm baffled.

Could you please explain why the controls collection has to be looped backwords ???

 

THanks a mil.

 

Cire

Trust the Universe
Posted

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

Trust the Universe

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...