1

Hi I'm still quite new to VB.NET... I have the following code for a form that has a button (Button1). When I press this button it adds a combobox with some values (it adds a new one underneath each time the button is pushed). How do I set up and event so that when a combobox is changed, a textbox will appear to the right of it? I'm basically looking at having different behaviors based on what is selected in each combobox.

Public Class frmEditor
    Private Const rowHeight = 25
    Dim datarows() As Action
    Dim currentrow As Integer
    Dim starttop As Integer
    Private Sub frmEditor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        currentrow = 1
        starttop = 20
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        CreateRow()
        currentrow = currentrow + 1
        starttop = starttop + rowHeight
    End Sub

    Private Sub CreateRow()
        Dim newrow As Action = New Action()
        ReDim Preserve datarows(currentrow)
        datarows(currentrow) = newrow
        datarows(currentrow).newAction(15, starttop, currentrow)
    End Sub

End Class

Public Class Action
    Private cbo As New ComboBox()

    Public Sub newAction(ByVal xleft As Integer, ByVal ytop As Integer, ByVal nrow As Integer)
        cbo.Top = ytop
        cbo.Left = xleft
        cbo.Visible = True
        cbo.Items.Add("Test1")
        cbo.Items.Add("Test2")
        frmEditor.Controls.Add(cbo)

    End Sub
End Class

1 Answer 1

0

You need to add a handler

AddHandler cbo.newAction, AddressOf newAction

EDIT:

Here is an example of something I built. I wanted to be able to add a row of links to the bottom of every page without having to add the HTML to each page. So I built a control to do it for me. Part of it was to add a LoginStatus control

        Protected Overrides Sub CreateChildControls()
           Dim lb As New LoginStatus
           With lb
               .ID = "LoginStatus1"
               AddHandler .LoggingOut, AddressOf LoginStatus1_LoggingOut
           End With
           Me.Controls.Add(lb)
        End Sub

Then my LoggingOut handler does a little magic as to not break my URLRewriting.

        Private Sub LoginStatus1_LoggingOut(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LoginCancelEventArgs)
        'sign out the logged in user
        End Sub
1
  • Ah yes I figured it out now. Thanks. I added: AddHandler cbo.SelectedValueChanged, AddressOf ChangeCombo to the newAction method and Created a new method called ChangeCombo Feb 13, 2010 at 1:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.