How to add a new control within a do while

  • Thread starter Thread starter Rob
  • Start date Start date
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 ?
 
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.
 
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.
 
Back
Top