473,503 Members | 1,136 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 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
3 957
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5256
by: Ben | last post by:
My current project requires me to create part of a form that is created on the fly. The project consists a list of entries to an event. The name and address and such is easy. The design is detup so...
19
4065
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
3
2413
by: Kenton Smeltzer | last post by:
Hello All, I am having a problem with events and the addition of controls on a page I am developing. First let me tell you what I have tried and then maybe someone can see something I missed. ...
1
1989
by: hybrid | last post by:
I have problems in understanding the behavior of the events triggered by dynamically created controls over a webform. Could you help me? In a webform, I have a static PlaceHolder PH containing...
2
4313
by: RAJ | last post by:
In our multi-tier application, we have several ASP.NET user controls which will update the same data source provided by middle tier logic. In this particular scenario we have one user control...
3
1490
by: msnews.microsoft.com | last post by:
Hello All, I am trying to write Web Controls and in most of the samples I came across, I am seeing the following function where a HTML string is written to create HTML Controls. ///...
5
1710
by: snesbit | last post by:
If a screen is made up of several user controls and those user controls contain various packaged or standard controls such as a grid, how do you raise both standard and custom events from the user...
53
4595
by: Hexman | last post by:
Hello All, I'd like your comments on the code below. The sub does exactly what I want it to do but I don't feel that it is solid as all. It seems like I'm using some VB6 code, .Net2003 code,...
3
2445
by: Jose Fernandez | last post by:
Hello. I would like to know how could i get all the subscriptions that my form has with the events of their controls. For example. I have a form with a textbox, a button and a dropdown. I...
5
6743
by: Amoril | last post by:
I've read quite a few different message on various boards and for some reason I'm still having trouble wrapping my head around this viewstate maintenance and trying to get these dynamically created...
0
7203
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7089
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7282
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7463
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5581
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5017
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3157
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1515
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
389
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.