slowNsteady
Programmer
Hi
I have a problem in handling the events for dynamically created controls
I am creating a combobox and a textbox dynamically when i click a Button1
for each combobox there is one corresponding textbox
so the number of times i click Button1 i will get that many number of comboboxes and textboxes.
i have added an Event handler to handle the ComboBox_SelectedIndexChanged
Whenever i click any of the combobox the above event is triggered.
So far it is working fine.
Now comes the problem
i have to get the selected item for each combobox in the appropriate textbox
i am not getting it
here is my code
Thanks in advance
Sri
I have a problem in handling the events for dynamically created controls
I am creating a combobox and a textbox dynamically when i click a Button1
for each combobox there is one corresponding textbox
so the number of times i click Button1 i will get that many number of comboboxes and textboxes.
i have added an Event handler to handle the ComboBox_SelectedIndexChanged
Whenever i click any of the combobox the above event is triggered.
So far it is working fine.
Now comes the problem
i have to get the selected item for each combobox in the appropriate textbox
i am not getting it
here is my code
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
combobox1 = New ComboBox
textbox1 = New TextBox
combobox1.Name = "combobox" & i
textbox1.Name = "textbox" & i
i = i + 1
combobox1.Location = New Point(31, 32 + x)
textbox1.Location = New Point(165, 32 + x)
x = x + 40
combobox1.Size = New Size(121, 21)
textbox1.Size = New Size(100, 21)
AddHandler combobox1.SelectedIndexChanged, AddressOf Me.ComboBox_SelectedIndexChanged
'AddHandler textbox1.TextChanged, AddressOf Me.TextBox1_TextChanged
Me.Controls.Add(combobox1)
Me.Controls.Add(textbox1)
combobox1.Items.Add("1")
combobox1.Items.Add("2")
combobox1.Items.Add("3")
combobox1.Items.Add("4")
combobox1.Items.Add("5")
combobox1.Items.Add("6")
End Sub
Private Sub ComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
If TypeOf sender Is ComboBox Then
Dim cb As ComboBox = DirectCast(sender, ComboBox)
textbox1.Text = cb.SelectedItem
End If
End Sub
Thanks in advance
Sri