Solved

VB.NET Control Array Help

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…

839 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