Advertisement

05.22.2008 at 03:39PM PDT, ID: 23426132
[x]
Attachment Details

Handeling user controls event click when added dynamically

Asked by tru3533 in Microsoft Visual Basic.Net

Tags: VB.NET

Hallo Experts,
I have made a User Control containing Button1and textbox1
Then added the following code to the control:
________________________________________________
Public Class button_panel
    Inherits System.Windows.Forms.UserControl
    Public Property txtValue() As String
        Get
            Return TextBox1.Text
        End Get
        Set(ByVal value As String)
            TextBox1.Text = value
        End Set
    End Property
End Class
________________________________________________



In the form I have the code:
_______________________________________________
  Private Sub ModularPortal_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
        Create_buttons()
        Create_buttons()
    End Sub
    Private MNButtonCount As Integer = 0
    Private Sub Create_buttons()
        Dim NewButton As New button_panel()
        NewButton.Location = New System.Drawing.Point(12, 204 + MNButtonCount)
        AddHandler NewButton.Click, AddressOf alfa
        Me.mnupanel.Controls.Add(NewButton)
        MNButtonCount += 100
    End Sub
    Public Sub alfa(ByVal sender As Object, ByVal e As EventArgs)
        sender.txtValue = "OK"
    End Sub
__________________________________________________________

When running, 2 buttons and2  textfields is made, with background from the User Control.
By clicking on one of the buttons, "Public Sub alfa" is not triggered.
If I click on the panel beside the buttons on the background from the User Control. "Public Sub alfa" is triggered and writing back to the correct User Control text field.

How do I redirect the button click event to trigger Public Sub alfa ?

Start Free Trial
[+][-]05.22.2008 at 09:55PM PDT, ID: 21629480

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.23.2008 at 01:34AM PDT, ID: 21630393

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.23.2008 at 01:55AM PDT, ID: 21630456

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.23.2008 at 02:03AM PDT, ID: 21630490

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Visual Basic.Net
Tags: VB.NET
Sign Up Now!
Solution Provided By: rachitkohli
Participating Experts: 1
Solution Grade: A
 
 
[+][-]05.23.2008 at 02:15AM PDT, ID: 21630533

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628