[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Event porcedures for dynamically created buttons

Posted on 2005-04-21
3
Medium Priority
?
262 Views
Last Modified: 2010-04-23
I am writing a program the when the use selects a report from a list  control array is created then added to another forms control collection. The controls are used for collecting the parameters needed for the report. If the parameter is multivalued I have created a text box, two buttons (add/remove) and a list box. How do I create the click event procedure for these buttons or is there a better way to do this. Some of the code is below.
 If newParameterFieldDefinition.EnableAllowMultipleValue Then
                I = I + 3
                ReDim ctlNewList(I)
                ctlNewList(I - 4) = New System.Windows.Forms.Label
                ctlNewList(I - 4).Text = newParameterFieldDefinition.PromptText
                ctlNewList(I - 3) = New System.Windows.Forms.TextBox
                ctlNewList(I - 2) = New System.Windows.Forms.Button
                ctlNewList(I - 2).Text = "ADD >>"
                ctlNewList(I - 1) = New System.Windows.Forms.Button
                ctlNewList(I - 1).Text = "<< REMOVE"
                ctlNewList(I) = New System.Windows.Forms.ListBox
                ctlNewList(I).Tag = newParameterFieldDefinition.Name
                frmParameters.Controls.Add(ctlNewList(I - 4))
                frmParameters.Controls.Add(ctlNewList(I - 3))
                 frmParameters.Controls.Add(ctlNewList(I - 2))
                frmParameters.Controls.Add(ctlNewList(I - 1))
                frmParameters.Controls.Add(ctlNewList(I))
0
Comment
Question by:Iron01
3 Comments
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13835996
first of all... is I  just a count for the number of added controls in your form?

... and im a little slow here, the add/remove buttons that you need the handlers for (you use addhandler/removehandler for that by the way, im sure you'll get some code posted up soon) ...  what are they adding/removing  ?
0
 
LVL 5

Expert Comment

by:KeirGordon
ID: 13836828
You use the addhandler function.

Read about it in your help file.

addhandler control_to_handle, function_to_call


0
 
LVL 28

Accepted Solution

by:
iboutchkine earned 2000 total points
ID: 13837178
Here is an exampl how to add dynamically buttons and then add handlers to them for the click event

Private ButtonArray(9) As Button

Public Sub AddButtons()
    For x As Integer = 0 To 9
        ButtonArray(x) = New Button
        With ButtonArray(x)
            .Tag = x
            .Text = "Button " & x
            .Size = New Size(60,20)
            .Location = New Point(20, (x * 20) + 4)
            .Parent = Me
            .Visible = True
            AddHandler .Click, AddressOf ButtonHandler
        End With
    Next        
End Sub

'Then, create a ButtonHandler to handle the button clicks

Public Sub ButtonHandler(ByVal sender As System.Object, ByVal e As
System.EventArgs)
    MsgBox("Button number " & CType(sender,Button).Tag & " was clicked")
End Sub
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month18 days, 16 hours left to enroll

834 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