Hello,

I am working on desktop application. I had created number of dynamic textbox and label and I want to save that data on clicking the save button.

If any question, if you did not get my point clear than please ask. Its urgent. Please Help!!!
Please give me suggestion and help me to work on these.
It would be pleased and appreciated to any help

Thanks in advance..

What data are you trying to save and do you have a particular form you want to use (text file, per user settings etc). Are you trying to save the controls themselves for later use or just the data in those controls? If just the data, what do you want to do with that data? Will it be reloaded when the app is rerun?

Member Avatar for CurtisUN

Hi,
One method of getting the data from a dynamically created textbox is using a code simular to this.

  dim retrievedtext() as string 
  dim NofTB as integer
  For Each c In Controls
                Dim ControlType As Type = c.[GetType]()
                Dim case1 As String = ControlType.Name
            If case1 = "TextBox" Then
            NofTB += 1
            retrievedtext(NofTB) = c.text
            End If
        Next

The data from all the textboxes will be in the array retrieved and accessable for saving. This code iterates through all the controls on your form to find the textboxes then put the data for that textbox into the array. Since I don't know the names of your textboxes I would not be able to give you a better example but you retrieve data from any textbox either created dynamically or through the use of tools during design by using the textbox name and .text.

Curtis

A better way to iterate over a set of particular controls is

For Each tb As TextBox In Me.Controls.OfType(Of TextBox)()
Member Avatar for CurtisUN

Thanks for the update in the code.
Curtis

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.