473,756 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Events for runtime created controls.

Tym
I have a piece of code thus:

For iLOOP = 0 To iNoDays - 1
For jLOOP = 0 To iMaxPeriods - 1
iX = 10 + (iLOOP * (dCellWidth + 10))
iY = 10 + (jLOOP * (dCellHeight + 10)) +
Me.Size.Height / 4
If jLOOP = 0 And iLOOP = 0 Then
lblDISPLAY(((iL OOP) * iMaxPeriods) + jLOOP) = New
TextBox
lblDISPLAY(((iL OOP) * iMaxPeriods) + jLOOP).Text =
" "
lblDISPLAY(((iL OOP) * iMaxPeriods) +
jLOOP).Location = New Point(iX, iY)
lblDISPLAY(((iL OOP) * iMaxPeriods) +
jLOOP).AutoSize = False
lblDISPLAY(((iL OOP) * iMaxPeriods) + jLOOP).Height
= dCellHeight
lblDISPLAY(((iL OOP) * iMaxPeriods) + jLOOP).Width
= dCellWidth
lblDISPLAY(((iL OOP) * iMaxPeriods) +
jLOOP).Visible = False
lblDISPLAY(((iL OOP) * iMaxPeriods) + jLOOP).Name =
"txtPERIOD" & ((iLOOP) * iMaxPeriods) + jLOOP.ToString
Me.Controls.Add (lblDISPLAY(((i LOOP) * iMaxPeriods)
+ jLOOP))
Else
If jLOOP = 0 And iLOOP > 0 Then
lblDISPLAY(((iL OOP) * iMaxPeriods) + jLOOP) =
New TextBox
lblDISPLAY(((iL OOP) * iMaxPeriods) +
jLOOP).Text = WeekdayName(iLO OP, , FirstDayOfWeek. Sunday)
lblDISPLAY(((iL OOP) * iMaxPeriods) +
jLOOP).Location = New Point(iX, iY)
lblDISPLAY(((iL OOP) * iMaxPeriods) +
jLOOP).Height = dCellHeight
lblDISPLAY(((iL OOP) * iMaxPeriods) +
jLOOP).Width = dCellWidth
lblDISPLAY(((iL OOP) * iMaxPeriods) +
jLOOP).AutoSize = False
lblDISPLAY(((iL OOP) * iMaxPeriods) +
jLOOP).BorderSt yle = BorderStyle.Non e
lblDISPLAY(((iL OOP) * iMaxPeriods) +
jLOOP).TextAlig n = HorizontalAlign ment.Center
lblDISPLAY(((iL OOP) * iMaxPeriods) +
jLOOP).Name = "txtPERIOD" & ((iLOOP) * iMaxPeriods) + jLOOP.ToString
Me.Controls.Add (lblDISPLAY(((i LOOP) *
iMaxPeriods) + jLOOP))
Else
If iLOOP = 0 And jLOOP > 0 Then
lblDISPLAY(((iL OOP) * iMaxPeriods) +
jLOOP) = New TextBox
lblDISPLAY(((iL OOP) * iMaxPeriods) +
jLOOP).Text = "Period " & jLOOP.ToString
lblDISPLAY(((iL OOP) * iMaxPeriods) +
jLOOP).Location = New Point(iX, iY)
lblDISPLAY(((iL OOP) * iMaxPeriods) +
jLOOP).Height = dCellHeight
lblDISPLAY(((iL OOP) * iMaxPeriods) +
jLOOP).Width = dCellWidth
lblDISPLAY(((iL OOP) * iMaxPeriods) +
jLOOP).AutoSize = False
lblDISPLAY(((iL OOP) * iMaxPeriods) +
jLOOP).BorderSt yle = BorderStyle.Non e
lblDISPLAY(((iL OOP) * iMaxPeriods) +
jLOOP).TextAlig n = HorizontalAlign ment.Right
lblDISPLAY(((iL OOP) * iMaxPeriods) +
jLOOP).Name = "txtPERIOD" & ((iLOOP) * iMaxPeriods) + jLOOP.ToString
Me.Controls.Add (lblDISPLAY(((i LOOP) *
iMaxPeriods) + jLOOP))
Else
lblDISPLAY(((iL OOP) * iMaxPeriods) +
jLOOP) = New TextBox
lblDISPLAY(((iL OOP) * iMaxPeriods) +
jLOOP).Text = "Label No " & ((iLOOP) * iMaxPeriods) + jLOOP.ToString
lblDISPLAY(((iL OOP) * iMaxPeriods) +
jLOOP).Location = New Point(iX, iY)
lblDISPLAY(((iL OOP) * iMaxPeriods) +
jLOOP).Height = dCellHeight
lblDISPLAY(((iL OOP) * iMaxPeriods) +
jLOOP).Width = dCellWidth
lblDISPLAY(((iL OOP) * iMaxPeriods) +
jLOOP).AutoSize = False
lblDISPLAY(((iL OOP) * iMaxPeriods) +
jLOOP).Name = "txtPERIOD" & ((iLOOP) * iMaxPeriods) + jLOOP.ToString
Me.Controls.Add (lblDISPLAY(((i LOOP) *
iMaxPeriods) + jLOOP))
End If
End If
End If
Next jLOOP
Next iLOOP

which creates a grid of text boxes on a form at runtime dependent on
the number of days and the number of periods - its a timetable sort of
thing.

How do I capture events for these controls?
such as
private sub lblDISPLAY(((iL OOP) * iMaxPeriods)_Mo useclick

or

private sub lblDISPLAY(((iL OOP) * iMaxPeriods)_go tfocus

??
Nov 21 '05
16 1227
Tym,
I would make the original array lblDISPLAY from your original code a class
(Form) level variable. Then index into it to get a specific TextBox.

Looking at your original code, I would probably make the original array a
two dimensional array (days & periods).

Something like:

Private lblDISPLAY(,) As TextBox

Private Sub CreateTextBoxes (...)
...
ReDim lblDISPLAY(iNoD ays -1, iMaxPeriods -1)
For iLOOP = 0 To iNoDays - 1
For jLOOP = 0 To iMaxPeriods - 1
...
If jLOOP = 0 And iLOOP = 0 Then
lblDISPLAY(iLOO P, jLOOP) = New TextBox
lblDISPLAY(iLOO P, jLOOP).Text = " "

...

Next jLOOP
Next iLOOP
...
End Sub

Also, rather then using iLOOP & jLOOP, I would probably call them dayIndex &
periodIndex, as IMHO it makes the code easier to read:

For dayIndex = 0 To iNoDays - 1
For periodIndex= 0 To iMaxPeriods - 1
...
lblDISPLAY(dayI ndex, periodIndex) = New TextBox
Then elsewhere:

lblDISPLAY(1,2) .Text = "New Value"

Unfortunately you cannot index a control collection by name, as name is just
another "Tag" property. You could use a For Each loop to loop for a control
with a specific name or you could maintain a HashTable that maps names to
TextBoxes:

Something like:

lblDISPLAY(iLOO P, jLOOP).Name = ...
Me.Controls.Add (lblDISPLAY(iLO OP,jLOOP))
hashDISPLAY.Add (lblDISPLAY(iLO OP, jLOOP).Name, lblDISPLAY(iLOO P, jLOOP))

Where hashDISPLAY is a class (Form) level System.Collecti ons.HashTable
variable.

Hope this helps
Jay
"Tym" <bi********@mic rosoft.com> wrote in message
news:r3******** *************** *********@4ax.c om...
On Tue, 2 Nov 2004 17:06:00 -0600, "Jay B. Harlow [MVP - Outlook]"
<Ja************ @msn.com> wrote:
labelDISPLAY. Name returns a string, there is no real need to call ToString
on it.


Yes - thanks. I realised that afterwards!!

Ok, so now I've got an event handler, how easy is it to refer to these
textboxes within my code elsewhere?

Normally, I would code:

If txtTextBox.Text = "Some Text" then
'my procedure....
End If

But as the name of the control is determined at runtime, I can't see a
straightworward way of doing this.

Sorry to bother you again...

Nov 21 '05 #11
Tym
Thanks Jay - it's worked a treat

If you're ever in the UK - remind me i owe you a beer!
Nov 21 '05 #12
Tym
On Wed, 03 Nov 2004 20:37:42 +0000, Tym <bi********@mic rosoft.com>
wrote:
Thanks Jay - it's worked a treat

If you're ever in the UK - remind me i owe you a beer!


You can make it two, if you can answer this one though...

I need to be able to set the locked property to true/false but keep
getting the message

'Locked' is not a member of 'windows.system .forms.textbox'

How can I access the .locked property?

I am declaring it as

Public txtDISPLAY(,) As TextBox

(Changed it from lblDISPLAY as it's now a textbox and not a lable!!)

advTHANKSance
Nov 21 '05 #13
Tym,
"Locked" is a designer property, it is not a runtime property. Its used to
help avoid inadvertently changing your design, when designing forms.

http://msdn.microsoft.com/library/de...rolsToForm.asp

What are you expecting the "Locked" property to do for you at runtime?

Hope this helps
Jay

"Tym" <bi********@mic rosoft.com> wrote in message
news:23******** *************** *********@4ax.c om...
On Wed, 03 Nov 2004 20:37:42 +0000, Tym <bi********@mic rosoft.com>
wrote:
Thanks Jay - it's worked a treat

If you're ever in the UK - remind me i owe you a beer!


You can make it two, if you can answer this one though...

I need to be able to set the locked property to true/false but keep
getting the message

'Locked' is not a member of 'windows.system .forms.textbox'

How can I access the .locked property?

I am declaring it as

Public txtDISPLAY(,) As TextBox

(Changed it from lblDISPLAY as it's now a textbox and not a lable!!)

advTHANKSance

Nov 21 '05 #14
Tym
On Sat, 6 Nov 2004 09:45:51 -0600, "Jay B. Harlow [MVP - Outlook]"
<Ja************ @msn.com> wrote:

What are you expecting the "Locked" property to do for you at runtime?


Ah!

I was expecting it to be the same as in VB6 - stop text input into the
text boxes until, say, the "edit" button is clicked.

in vb6 txtTEXT1.Locked = True, used to allow this, with
txtTEXT1.Locked = false enabling text entry

The problem with the .ReadOnly = True/False, is that is changes the
background colour of the text box, which I didn't really want to do,
but am using it for now.
Nov 21 '05 #15
Tym,
Have you tried setting ReadOnly to true, then setting the BackGround color
to the color you want?

In VS.NET 2003 I had to select a different color for BackGround the select
BackGround = System.Window, otherwise it worked.

Hope this helps
Jay

"Tym" <bi********@mic rosoft.com> wrote in message
news:q8******** *************** *********@4ax.c om...
On Sat, 6 Nov 2004 09:45:51 -0600, "Jay B. Harlow [MVP - Outlook]"
<Ja************ @msn.com> wrote:

What are you expecting the "Locked" property to do for you at runtime?


Ah!

I was expecting it to be the same as in VB6 - stop text input into the
text boxes until, say, the "edit" button is clicked.

in vb6 txtTEXT1.Locked = True, used to allow this, with
txtTEXT1.Locked = false enabling text entry

The problem with the .ReadOnly = True/False, is that is changes the
background colour of the text box, which I didn't really want to do,
but am using it for now.

Nov 21 '05 #16
Tym
On Mon, 8 Nov 2004 10:59:05 -0600, "Jay B. Harlow [MVP - Outlook]"
<Ja************ @msn.com> wrote:
Tym,
Have you tried setting ReadOnly to true, then setting the BackGround color
to the color you want?


Looks like that may be the way to go.

Thinking about it though... having the background colour different for
edit/non edit makes it a little clearer I suppose... :-)
Nov 21 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2005
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 a table of controls, dynamically generated. Among these, a linkbutton (LinkBtn) to which have attached a click handler method, LinkBtn_Click(...) . Generally it works fine, but if in the LinkBtn_Click(...) code I try to access a webform control,...
4
2561
by: blue | last post by:
I have a drop-down list, a radio button list and a submit button. I'm adding these controls to a table and I'm adding the table to a Placeholder. I'm adding it to the Placeholder because I don't know exactly where the table will be located on the page until runtime. Before the form control table is added to the Placeholder, I'm adding a whole bunch of tables to the Placeholder. This is a flowchart program and I have multiple action boxes...
5
1717
by: karthick raja | last post by:
Am experiencing a problem intercepting the events from controls added dynamically to a Placeholder control at runtime. Is there any way that I can write an event handler on the page which will be pick up the events raised by the added controls dynamically. I cannot use 'WithEvents' and 'Handles' because this requires that the controls be declared on the page and they aren't (they are created in the external class) I did think of using...
0
1449
by: Klaus Jensen | last post by:
Hi! This has been annoying me for a while now, and I can't get it to work It is really driving me nuts! Basicly this simple webapp created to illustrate my problem, renders five buttons, and adds a handler to the click event. When a button is clicked, the background-color is set to blue.
1
1037
by: krishna | last post by:
Hi, Hi, I would like to handle the events for the dynamically created controls at runtime. I Have written the code in HTML View of an asp.net page.like this
0
1092
by: Steve Moreno | last post by:
Hi all, I've got a web form that I've written code to create an array of DropDownList controls on the page depending on how many records are pulled back. The code to create the controls is working fine but now I need to add events to the newly created DropDownList controls. I need to add the SelectedIndexChanged event and I'm having a hard time getting the code to add events to the controls since the names (IDs) are varied to include...
7
1759
by: Bruce HS | last post by:
I'd like to call my ancestor Validation Function every time any control on a Win Form generates a Validating or Validated event. I'm using VB. I've extended Textbox, for instance, to have its events do this for me, but my extended textbox doesn't get created by those wonderful form setup wizards. So, 1) Is there a way I can pick up these events without having to code for each control and without using custom extended controls, OR
3
2466
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 create a subscription to the Click event of the Button and another to the SelectedIndexChanged del dropDown.
1
1730
by: Klaus Jensen | last post by:
Subject: Handling events of controls created at runtime I need to render some buttons at runtime based on a database, tie events to them, and handle the events when they fire. In Page_Load I create the controls (for example a delete-button), add them to a placeholder, add eventhandlers, and the controls are displayed as expected. I click the button, the event fires as I wanted, I delete a record in the
0
9456
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9275
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9872
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9713
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8713
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7248
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3805
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 we have to send another system

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.