Solved

VB.NET Control Array Help

Posted on 2004-10-08
4
156 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now