hi,
I am new to this forum but i have received a lot of help reading through this forum. I am creating a VB.NET application for Patient Record Management. In this there are various combo boxes and buttons being generated during run time when a particular patient ID is searched for. Say one patient might have 2 entries some may have 10 entries. So the controls are generated dynamically and then the control names are added to the forms collection(Me.Controls.Add(txtDataShow))
I am looking for is generating functions during runtime which can handle say a clicking of the button which was generated during runtime. some thing like
Private Sub btnAddDiag_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs)
Handles (dynamicbutton).Click
where dynamicbutton will be the name of the button the user clicks.
Appreciate your help.
2 6103
It depends on the object you're handling...but here's the jist of it... -
Private Sub MyEventHandler(ByVal Sender As Object, ByVal e As System.EventArgs) 'The System.EventArgs may change depending upon the event you handle and what type of object...
-
'Do stuff
-
End Sub
-
-
'In your sub where you add your object
-
Dim oObj As New Object 'Replace Object with the type of object you require.
-
AddHandler oObj.Event, AddressOf MyEventHandler
-
Instead of attaching the Handles clause on the end of your event handler sub, you effectively attach the event handler dynamically at the time the object is instantiated. A for instance - if you're adding a button to your page and wish to handle the click event of that button: - Private Sub MyClickHandler(ByVal Sender As Object, ByVal e As System.EventArgs) 'Notice there's no handles clause here
-
MsgBox "You clicked "& CType(Sender, Button).ID & "."
-
End Sub
-
-
Sub Page_Load(ByVal Sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
For n As Integer = 1 To 10
-
Dim oBtn As New Button
-
oBtn.ID = "Button"& n
-
oBtn.Text = "Click me!"
-
AddHandler oBtn.Click, Addressof MyClickHandler
-
Form1.Controls.Add(oBtn)
-
Next
-
End Sub
It depends on the object you're handling...but here's the jist of it... -
Private Sub MyEventHandler(ByVal Sender As Object, ByVal e As System.EventArgs) 'The System.EventArgs may change depending upon the event you handle and what type of object...
-
'Do stuff
-
End Sub
-
-
'In your sub where you add your object
-
Dim oObj As New Object 'Replace Object with the type of object you require.
-
AddHandler oObj.Event, AddressOf MyEventHandler
-
Instead of attaching the Handles clause on the end of your event handler sub, you effectively attach the event handler dynamically at the time the object is instantiated. A for instance - if you're adding a button to your page and wish to handle the click event of that button: - Private Sub MyClickHandler(ByVal Sender As Object, ByVal e As System.EventArgs) 'Notice there's no handles clause here
-
MsgBox "You clicked "& CType(Sender, Button).ID & "."
-
End Sub
-
-
Sub Page_Load(ByVal Sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
For n As Integer = 1 To 10
-
Dim oBtn As New Button
-
oBtn.ID = "Button"& n
-
oBtn.Text = "Click me!"
-
AddHandler oBtn.Click, Addressof MyClickHandler
-
Form1.Controls.Add(oBtn)
-
Next
-
End Sub
The code AddHandler oBtn.Click, Addressof MyClickHandler works pefectly and is exactly what i needded. I used it where i was creating the buttons dynamically and it does add the click function during runtime. Thanks a lot. You saved me a lot of trouble.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: dog |
last post by:
I've seen plenty of articles on this topic but none of them have been
able to solve my problem.
I am working with an Access 97 database on an NT4.0 machine, which has
many Access reports.
I...
|
by: leon |
last post by:
hello friends, i am writing a page aspx and creating controls dinamicaly and
then
i must to create for each control the events as well.
Anybody to know how?????
happy day
lion
|
by: RSB |
last post by:
Hi Every one
Having tuff time creating web controls Dynamically. All i am trying to do is
read a table and generate a list of ASP TEXT Box.
So how do i create this Control dynamically and where...
|
by: eliss.carmine |
last post by:
Is it possible to simulate a mouse click in the window I made (it's a
Form), but not give it focus?
I tried using WinAPI's mouseevent and SendMessage of
WM_LBUTTONDOWN/WM_LBUTTONUP as suggested...
|
by: William Foster |
last post by:
Good evening all,
I am creating a program with the ability to select an option from a
ComboBox which will then create a secondary list of options in a
CheckedListBox. Previously when I have...
|
by: SM |
last post by:
Hello
I'm trying to create a multi dimensional array in JavaScript, but
after some reading i still can't figure out how to apply it to my
model.
Here it is:
I have a list A and for each item...
|
by: Matt |
last post by:
Hi all,
I'm trying to create a system where it reads a number of records from
a database and then creates a row in the GUI that contains a single
field from the database and a button that has a...
|
by: MaryamSh |
last post by:
Hi,
I am creating a Dynamic Search in my application.
I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove)
By pressing Add button...
|
by: MaryamSh |
last post by:
Create Dynamic Dropdownlist Controls and related event
--------------------------------------------------------------------------------
Hi,
I am creating a Dynamic Search in my application.
I...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
|
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,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |