I'm trying to add a textbox and a label during runtime when the users presses a button. When I press the button a label and textbox is created, when I click it again nothing happens. Here is the code I have:
The default label and default combobox move down, but it wont create another label and textbox. Any ideas?
vb.net Code:
[CODE] Dim CreatedGroupBox As New GroupBox Dim CreatedCombobox As ComboBox Dim CreatedTextBox As TextBox Dim CreatedCheckBox As CheckBox Dim CreatedRadioButton As RadioButton Dim RadioButtonCount As Integer Dim DetailsLabel As Label Dim DetailsTextbox As TextBox Dim DetailsButton As New Button Dim DetailsCombobox As New ComboBox Private Sub radRadioButton_CheckedChanged(sender As Object, e As EventArgs) Handles radRadioButton.CheckedChanged If radRadioButton.Checked = True Then '//SETUP DETAILS grpDetails.Controls.Clear() '//Radiobutton 1 label's label DetailsLabel = New Label DetailsLabel.Name = "lblRadioButtonName" & RadioButtonCount DetailsLabel.Text = "Radio Button " & RadioButtonCount + 1 & " label:" DetailsLabel.AutoSize = True DetailsLabel.Location = New Point(6, 22) grpDetails.Controls.Add(DetailsLabel) '//Radio button 1 label's textbox DetailsTextbox = New TextBox DetailsTextbox.Name = "txtRadioButtonName" & RadioButtonCount DetailsTextbox.Text = "Radio Button " & RadioButtonCount + 1 DetailsTextbox.Location = New Point(DetailsLabel.Location.X + DetailsLabel.Width, 19) AddHandler DetailsTextbox.TextChanged, AddressOf RadioButtonName grpDetails.Controls.Add(DetailsTextbox) '//Add radiobutton button DetailsButton.Text = "+" DetailsButton.Name = "btnAddRadioButton" DetailsButton.Location = New Point(DetailsTextbox.Location.X + DetailsTextbox.Width + 5, 19) DetailsButton.Size = New Size(20, 20) AddHandler DetailsButton.Click, AddressOf AddRadioButton grpDetails.Controls.Add(DetailsButton) '//Add Detfault selection label DetailsLabel = New Label DetailsLabel.Name = "lblDefaultRadioButton" DetailsLabel.Text = "Default Radio Button:" DetailsLabel.AutoSize = True DetailsLabel.Location = New Point(6, DirectCast(Me.Controls.Find("lblRadioButtonName" & RadioButtonCount, True)(0), Label).Location.Y + 29) grpDetails.Controls.Add(DetailsLabel) '//Add Default selection combobox DetailsCombobox.Items.Add(DetailsTextbox.Text) DetailsCombobox.Location = New Point(DetailsLabel.Location.X + DetailsLabel.Width, DirectCast(grpDetails.Controls.Find("lblRadioButtonName" & RadioButtonCount, True)(0), Label).Location.Y + 25) DetailsCombobox.DropDownStyle = ComboBoxStyle.DropDownList DetailsCombobox.SelectedIndex = 0 grpDetails.Controls.Add(DetailsCombobox) RadioButtonCount += 1 End If End Sub Public Sub AddRadioButton(ByVal sender As System.Object, ByVal e As System.EventArgs) '//Move the default selection combobox and label and button down DetailsCombobox.Location = New Point(DetailsCombobox.Location.X, DetailsCombobox.Location.Y + 30) DirectCast(grpDetails.Controls.Find("lblDefaultRadioButton", True)(0), Label).Location = New Point(6, DetailsCombobox.Location.Y + 3) DetailsButton.Location = New Point(DetailsButton.Location.X, DetailsButton.Location.Y + 30) '//Create new label DetailsLabel = New Label DetailsLabel.Name = "lblRadioButtonName" & RadioButtonCount DetailsLabel.Text = "Radio Button " & RadioButtonCount + 1 & " label:" DetailsLabel.AutoSize = True DetailsLabel.Location = New Point(6, DirectCast(grpDetails.Controls.Find("lblRadioButtonName" & RadioButtonCount - 1, True)(0), Label).Location.X + 43) grpDetails.Controls.Add(DetailsLabel) '//Create new radio button DetailsTextbox = New TextBox DetailsTextbox.Name = "txtRadioButtonName" & RadioButtonCount DetailsTextbox.Text = "Radio Button " & RadioButtonCount + 1 DetailsTextbox.Location = New Point(DetailsLabel.Location.X + DetailsLabel.Width, DirectCast(grpDetails.Controls.Find("lblRadioButtonName" & RadioButtonCount - 1, True)(0), Label).Location.X + 40) AddHandler DetailsTextbox.TextChanged, AddressOf RadioButtonName grpDetails.Controls.Add(DetailsTextbox) RadioButtonCount += 1 End Sub[/CODE]
The default label and default combobox move down, but it wont create another label and textbox. Any ideas?