Solved

VB.NET Control Array Help

Posted on 2004-10-08
4
159 Views
Last Modified: 2010-04-23
I used the following Microsoft article to create a control array:

http://msdn.microsoft.com/library/default.asp?url=/library/en us/dv_vstechart/html/vbtchcreatingcontrolarraysinvisualbasicnetvisualcnet.asp

I modified it to have a row of labels and one button to display some information on a summary form. My form has 2 tabs. it loads up to the first tab and builds the summary adding how many rows to the array i need. I want the user to be able to click the button I added for each row and have the program show the other tab. The way the article sets it up, the event handlers for the array are in my SummaryArray class. How do i get the event handler in the class to control my form or how do I get a function on my form to handle events for the SummaryArray class?
0
Comment
Question by:m9s999
  • 2
  • 2
4 Comments
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 12274009
The link you posted is not opening
I think you need to Use AddHandler
Can you elaborate what exactly you want

0
 

Author Comment

by:m9s999
ID: 12275544
Lets try the link again.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchCreatingControlArraysInVisualBasicNETVisualCNET.asp?_r=1


The article uses AddHandler in the array class. I have that working. What i need is for the handler to do stuff on my parent form (switch tabs, load detail information).
0
 
LVL 19

Accepted Solution

by:
arif_eqbal earned 500 total points
ID: 12284851
See if you have the code already done and working and you do not want to mess with it All you can do is pass a reference of the Parent form to the class so that the event Handlers and other methods in the class can access the controls etc. of the Parent form.

In case you want to do this then create a public Variable in the Class
Public ParentForm as Form

then from the Parent Form when you create an instance of the class set ClassObject.ParenForm=me

Now you can use the ParentForm variable in the Class to modify/access the Parent form data/methods etc.

better still you make the ParentForm variable private and set it through a property or in Class Constructor.

Now another method is What I feel is you need not have the new class at all, In the same form you can add as many controls. But it will depend upon your exact equirement. In case you have a Form where you want to Add a few controls Dynamically and handle their events, you can procedd as follows:

Add a function in the Form

Private Sub AddControls ()

        Dim Txt As TextBox = New TextBox
        Txt.Name = "Txt1"
        Txt.Top = 10
        Txt.Left = 10
        Txt.Visible = True
        Me.Controls.Add(Txt)
        AddHandler Txt.TextChanged, AddressOf txtTextChanged

End Sub

 Private Sub txtTextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        MsgBox(sender.text)
 End Sub


Similarly you can go on Adding the Controls and Add their event handlers on the same form
since there certainly will be more than one control you need a logic to place the control i.e. the Top & Left property. You can decide to let it go in a flow layout way or whatever suits you. Also there can be a separate handler for each control or you can have the same Handler, In case of same Handler you can distinguish based on the Sender.name

0
 

Author Comment

by:m9s999
ID: 12304335
Great. I'll play around with it and see what I can do. Thanks.
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question