Solved

writting access database records to dynamic text boxes at run time.

Posted on 2004-10-05
3
202 Views
Last Modified: 2010-04-23
Hi All !!
How can i dynamically and at run time create n (n > 0 ) number of textboxes (maybe using dynamic control arrays) and write to those text boxes n records i just retrieve from my access database.

I need this as soon as you experts can otherwise i will get fired...:-)

Thanks

0
Comment
Question by:komlaaa
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
123654789987 earned 500 total points
ID: 12234798
To add Dynamic textboxes to your form, use a function like this.

 Public Function DynamicControlCreation(ByVal firstInt As Integer, _
        ByVal secondInt As Integer, ByVal newPoint As Integer) As Boolean
        Dim i As Integer
        Dim newTextBox As Integer
        Dim k As Integer
        Dim newLabel As Integer
        'The X coordinate where the first TextBox will appear.
        newTextBox = 425
        'The X coordinate where the first Label will appear.
        newLabel = 210
        'The Y coordinate of the Controls
        k = newPoint
        Try
            For i = firstInt To secondInt
                x = gbObservation.Controls.IndexOf(labelCollection(i))
                'Before new controls are added to the screen the existing controls
                'should be removed.
                If (x >= 0) Then
                    gbObservation.Controls.Remove(labelCollection(i))
                    gbObservation.Controls.Remove(textboxCollection(i))
                End If
                labelCollection(i) = New Label
                Me.labelCollection(i).Location = New System.Drawing.Point(newLabel, k)
                Me.labelCollection(i).Size = New System.Drawing.Size(215, 22)
                Me.labelCollection(i).TextAlign = ContentAlignment.MiddleRight
                Me.labelCollection(i).Font = New System.Drawing.Font _
                    ("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, _
                     System.Drawing.GraphicsUnit.Point, CType(0, Byte))
                Me.labelCollection(i).Text = frmSelectTraits.ReturnTraits(i)
                'Adding the dyanmically created labelCollection to the GroupBox
                gbObservation.Controls.Add(labelCollection(i))
                'The X coordinate of the point where the next label should appear.
                newLabel = newLabel + 285
            Next

            For i = firstInt To secondInt
                textboxCollection(i) = New TextBox
                Me.textboxCollection(i).Location = New System.Drawing.Point(newTextBox, k)
                Me.textboxCollection(i).Size = New System.Drawing.Size(70, 22)
                Me.textboxCollection(i).MaxLength = 12
                'adding the dynamically created textbox to the GroupBox.
                gbObservation.Controls.Add(textboxCollection(i))
                'The X coordinate of the point where the next textbox should appear.
                newTextBox = newTextBox + 285
            Next
            If Not Me.labelCollection(secondInt + 1) Is Nothing Then
                For i = secondInt + 1 To Me.labelCollection.Length - 1
                    gbObservation.Controls.Remove(labelCollection(i))
                    gbObservation.Controls.Remove(textboxCollection(i))
                Next
            End If
            Return True
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Function

U can call such function at form_load or on the click of a button.

Then u can retrieve the record from the database to a dataset.

then u can loop through the textboxes and insert the record into them

for i = 0 to textboxCollection.Count
textboxCollection(i) = dtTablr.Rows(0)(i).Tostring()
Next i
0
 

Author Comment

by:komlaaa
ID: 12237594
Thanks for your prompt reply!! ----

How do i get the count of number of fields in my table?

I haven't test this yet but eveything looks neat to me.

Thanks
0
 

Author Comment

by:komlaaa
ID: 12260170

What does this means in the code you provided?

Me.labelCollection(i).Text = frmSelectTraits.ReturnTraits(i)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question