By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,065 Members | 1,560 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,065 IT Pros & Developers. It's quick & easy.

Using events with controls created in code.

P: n/a
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 frmAddPeopleToGroup_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
CreateControls()
MakeTable()
End Sub
Private Sub CreateControls()
Static LocationStart As Integer = 50

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

For i = 0 To frmAddGroup.vbPeopleCount - 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!!
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Shawn,

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

http://groups-beta.google.com/group/...9f9ffb83?hl=en

I hope this helps,

Cor
Nov 21 '05 #2

P: n/a
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" <no************@planet.nl> wrote in message
news:eo****************@TK2MSFTNGP10.phx.gbl...
Shawn,

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

http://groups-beta.google.com/group/...9f9ffb83?hl=en
I hope this helps,

Cor

Nov 21 '05 #3

P: n/a
"Shawn" <sh**********@ccci.org> schrieb:
I am trying to raise enter events for a combobox control that I am
building
dynamically at run time.


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/>

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.