Solved

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

Posted on 2004-10-05
3
199 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Check if number is currency 15 31
Vb.Net Date Formatting Assistance 4 35
VB.net/WinForms: adjust Screen Resolution 6 40
scanning dentists xray (the small ones) 3 43
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

914 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now