Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all, I have created an Event handler to a function for clicking a generated button, now when this button is clicked need to paste in a textbox the Combobox.seleteditem (that it's a string. Each generated one (Combobox, textbox, button) will have a selected index of the Combobox that it's different, but that is not the problem because I put it in an if, the issues it's that I can't put inside this sub all the three-component. After all, it tells me that the windows form button cannot be a textbox, etc. Do I need to put another two event handlers for textbox and Combobox?

What I have tried:

Public Sub btn_Click(sender As System.Object, ByVal e As System.EventArgs)
        Dim btn As New Button
        btn = CType(sender, Button)
        Dim txt As New TextBox
        txt = CType(sender, TextBox)
        Dim cbx As New ComboBox
        cbx = CType(sender, ComboBox)
        TextBox4.Text += txt.Text
        TextBox4.Text += cbx.SelectedItem.ToString
    End Sub
Posted
Updated 6-Jan-22 12:44pm

1 solution

More than a solution it's a workaround
1)I changed the btn.click to cbx.selectedindexchanged but it will be instantly pasted into the textbox but have the same result except for the click (I'll wait for some other solution)
2)Make for some

Public Sub btn_Click(sender As System.Object, ByVal e As System.EventArgs)
        'Dim btn As New Button
        'btn = CType(sender, Button)
        'Dim txt As New TextBox
        'txt = CType(sender, TextBox)
        Dim cbx As New ComboBox
        cbx = CType(sender, ComboBox)
        TextBox4.Text += cbx.SelectedItem.ToString & vbCrLf
 
Share this answer
 
Comments
Richard Deeming 7-Jan-22 4:47am    
Why create a new ComboBox instance when you're just going to throw it away on the next line?
Dim cbx As ComboBox = CType(sender, ComboBox)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900