Solved

VB.NET Control Array Help

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

929 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

10 Experts available now in Live!

Get 1:1 Help Now