Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 623
  • Last Modified:

add controls at runtime

I am trying to add 3 controls in a form per record; at run time I read the table information and add the controls but only the last 3 controls are showing up in my form at the end. I am not sure what is the problem. Could somebody please help me please?
Here is my code:

 Dim lblCtrl As Label
 Dim txtbx1Ctrl As TextBox
 Dim txtbx2Ctrl As TextBox

Private Sub frmUtil_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim oraAircraftCmd As New OracleClient.OracleCommand
            oraAircraftCmd.Connection = oraConn
            oraAircraftCmd.CommandType = CommandType.Text
            oraAircraftCmd.CommandText = "SELECT * FROM MASTER ORDER BY AC"
            Dim oraACReader As OracleClient.OracleDataReader = oraAircraftCmd.ExecuteReader
            If oraACReader.HasRows = True Then
                While oraACReader.Read
                   

                    lblName = "lblAC" & oraACReader("AC").ToString
                    txtbx1Name = "txtbxHrs" & oraACReader("AC").ToString
                    txtbx2Name = "txtbxCyc" & oraACReader("AC").ToString

                    With Me.lblCtrl
                        .Name = lblName
                        .Location = New System.Drawing.Point(CtrlXlbl, CtrlYLoc)
                        .Text = oraACReader("AC").ToString
                    End With
                    lblCtrl = New Label
                    Me.Controls.Add(lblCtrl)
                    lblCtrl.Visible = True
                    'AddHandler lvlCtrl.Click, AddressOf lvlCtrl

                    With Me.txtbx1Ctrl
                        .Name = "txtbxHrs" & oraACReader("AC").ToString
                        .Location = New System.Drawing.Point(CtrlX1HrsLoc, CtrlYLoc)
                        .Size = New System.Drawing.Size(70, 22)
                    End With
                    txtbx1Ctrl = New TextBox
                    Me.Controls.Add(txtbx1Ctrl)
                    txtbx1Ctrl.Visible = True
                    With Me.txtbx2Ctrl
                        .Name = "txtbxCyc" & oraACReader("AC").ToString
                        .Location = New System.Drawing.Point(CtrlX2HrsLoc, CtrlYLoc)
                        .Size = New System.Drawing.Size(70, 22)
                    End With
                    txtbx2Ctrl = New TextBox
                    Me.Controls.Add(txtbx2Ctrl)
                    txtbx2Ctrl.Visible = True
                    CtrlYLoc = CtrlYLoc + 30

                End While
end sub
0
mwells08
Asked:
mwells08
1 Solution
 
YZlatCommented:
i don't see where you assign initial values to CtrlXlbl and CtrlYLoc. So it is possible that controls are added one on top of another
0
 
CodeCruiserCommented:
Move this line

             lblCtrl = New Label

to before

             With Me.lblCtrl

Similar for other two controls.
0
 
mwells08Author Commented:
Thank you both for your replies. Moving the line  lblCtrl = New Label before  With Me.lblCtrl
 worked.
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now