How to add a new control within a do while

R

Rob

I am doing something wrong....

I am trying to add a user defined control to a FlowLayoutPanel for each row
read in a do while loop...

What is happening is that only one control is getting added, not one for
each row.

' declare user defined variable
Dim aUser as New UserDefined1

'declare Flow Layout panel variable
Dim FLP as New FlowLayoutPanel

' Add the Flowlayoutpanel to the form
frm.controls.Add(FLP)

' set some properties of the FLP...
blah blah

' set up stored proc
blah blah


Do While dr.Read()

'This loop is working correctly because I have a msgbox report the
primary key

FLP.Controls.Add(aUser)

Loop


Any ideas ?
 
R

Ray Cassick

Move the definition of the control inside the loop. For Example:

Do While dr.Read()

Dim aUser as New UserDefined1

FLP.Controls.Add(aUser)

Loop

You may also want to wire up some event handlers at the time you add the
control also.
 
R

Rob

Thanks Ray, works well now !

Ray Cassick said:
Move the definition of the control inside the loop. For Example:

Do While dr.Read()

Dim aUser as New UserDefined1

FLP.Controls.Add(aUser)

Loop

You may also want to wire up some event handlers at the time you add the
control also.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top