views:

207

answers:

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
A: 

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
rockinthesixstring
Ah yes I figured it out now. Thanks.I added:AddHandler cbo.SelectedValueChanged, AddressOf ChangeComboto the newAction method and Created a new method called ChangeCombo
Mrgreen
Awesome... glad that worked.
rockinthesixstring