Solved

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

Posted on 2004-10-05
3
204 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

752 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