Using events with controls created in code.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Shawn

    #1

    Using events with controls created in code.

    Hello All,

    I am trying to raise enter events for a combobox control that I am building
    dynamically at run time. A user enters a number in a textbox and that many
    comboboxes are created. I then need to populate them with a database query,
    but can seem to find a way to get any more than the last control to respond.
    I have them being named differently, but only the base name shows for
    events. Below is my code...

    Dim WithEvents ctlComboBox As Control

    Private Sub frmAddPeopleToG roup_Load(ByVal sender As System.Object, ByVal e
    As System.EventArg s) Handles MyBase.Load
    CreateControls( )
    MakeTable()
    End Sub
    Private Sub CreateControls( )
    Static LocationStart As Integer = 50

    Dim vbFont As New Font("Baskervil le Old Face", 10)
    Dim i As Integer

    For i = 0 To frmAddGroup.vbP eopleCount - 1
    ctlComboBox = New ComboBox()
    With ctlComboBox
    .Name = "cmbPeople" & i
    .Location = New Point(20, LocationStart)
    .Width = 250
    .Font = vbFont
    End With

    LocationStart += 30
    Me.Controls.Add (ctlComboBox)
    Next
    End Sub

    Thanks!!


  • Cor Ligthert

    #2
    Re: Using events with controls created in code.

    Shawn,

    Look at this sample as I once made, the text in it is the same for you.



    I hope this helps,

    Cor


    Comment

    • Shawn

      #3
      Re: Using events with controls created in code.

      I don't know where my brain went on this one, but your code looks good. I
      will adapt it and try it out.

      Thanks!!!

      "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
      news:eoR%23eHEa FHA.3072@TK2MSF TNGP10.phx.gbl. ..[color=blue]
      > Shawn,
      >
      > Look at this sample as I once made, the text in it is the same for you.
      >
      >[/color]
      http://groups-beta.google.com/group/...9f9ffb83?hl=en[color=blue]
      >
      > I hope this helps,
      >
      > Cor
      >
      >[/color]


      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: Using events with controls created in code.

        "Shawn" <shawn.camner@c cci.org> schrieb:[color=blue]
        > I am trying to raise enter events for a combobox control that I am
        > building
        > dynamically at run time.[/color]

        Take a look at the 'AddHandler'/'RemoveHandler' statements:

        \\\
        Private Sub Test()
        Dim Button1 As New Button()
        With Button1
        .Location = New System.Drawing. Point(56, 88)
        .Name = "Button1"
        .Size = New System.Drawing. Size(144, 48)
        .TabIndex = 0
        .Text = "Button1"
        End With
        AddHandler Button1.Click, AddressOf Me.Button_Click
        Me.Controls.Add (Button1)
        End Sub

        Private Sub Button_Click( _
        ByVal sender As Object, _
        ByVal e As EventArgs _
        )
        MsgBox("Hello World")
        End Sub
        ///

        --
        M S Herfried K. Wagner
        M V P <URL:http://dotnet.mvps.org/>
        V B <URL:http://classicvb.org/petition/>

        Comment

        Working...