Creating controls during runtime

bcm

Well-known member
Joined
Aug 13, 2007
Messages
56
Programming Experience
Beginner
Can any one please help me in following in VB.NET2005:

I want that whenever the word setting appears a textbox would be created during runtime i.e here it appears for 4 times so 4 textboxes should be created, if it appears for 5 times then 5 textboxes would be created......
Can it be done using array? If yes then how?


<applicationSettings>
<WindowsApplication1.My.MySettings>
<setting name="Astrology" serializeAs="String">
<value>6</value>
</setting>
<setting name="Cricket" serializeAs="String">
<value>7</value>
</setting>
<setting name="Foreigncurrency" serializeAs="String">
<value>8</value>
</setting>
<setting name="Jobs" serializeAs="String">
<value>9</value>
</setting>
</WindowsApplication1.My.MySettings>
</applicationSettings>

Please help soon:confused:
 
You may get the SettingsPropertyCollection using My.Settings.Properties.

VB.NET:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim y As Integer = 10
        For Each setting As System.Configuration.SettingsProperty In My.Settings.Properties
            Dim myTextBox As New TextBox()
            myTextBox.Name = setting.Name
            myTextBox.Text = setting.DefaultValue
            myTextBox.Location = New Point(100, y)
            y += 50
            Me.Controls.Add(myTextBox)
        Next
    End Sub
End Class
 
Thank you very much.
But if I delete a node from app.config manually it does not reduces the textbox for e.g I delete the following node it shows 4 textboxes only
<setting name="Jobs" serializeAs="String">
<value>9:00</value>

can you tell me how and any change to it??

Also I want that a label to be created oppsite corresponding to value i.e corresponding to 6 label of Astrology, to 7 label of Cricket and to any which I create label of that.

Thank you for help &
Please help again
:confused:
 
Back
Top