Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-10-05
3
Medium Priority
?
210 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 2000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

926 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