Creating Events

Hi all,

I am trying to hook up an application i have created using Events but am a little unsure as to where to put everything. So any guidance in the right direction would be appreciated.

What i have is a form with two user controls, a textbox control and a data grid. what i am trying to do is when the user selects a customer from the text box control it will populate the datgrid with their details. I have declared a Public Event NewCustomer and Raised the event in the selected index change of the textbox control but am a little unsure as to where to go futher! Should i handle the event in the form class or the datagrid user control class

As a newbie any help is greatly received!



Answer this question

Creating Events

  • Imola

    It sounds like you are using a ListBox control not a TextBox. If the procedure is only used by the form handle it in the form. If it is a one time procedure only used by SelectedIndexChanged handle it directly in the SelectedIndexChanged sub (This sounds like the case). If it is used by multiple classes you may want to create a module for it.

    You cannot write directly to the DataGrid control class unless you create your own class and inherit the DataGrid. Under Help there is section called "How Do I in Visual Basic". Going thru the walkthru helped me a lot.

    Hope this helps!



  • Esraa

    You should have the event in the form that contains the "textbox" -select the usercontrol in the object dropdown in codeview and then select that event in the dropdown next to it - the ide will create the event template wrapper and you can put your code in there - in the form, the event is raised to the parent container (a form in this case).

    ie. (label placed on user control, usercontrol placed on a form)

    Public Class UserControl1

    Public Event SomethingHappened()

    Private Sub Label1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label1.Click

    RaiseEvent SomethingHappened()

    End Sub

    End Class

    'this in the form

    Private Sub UserControl11_SomethingHappened() Handles UserControl11.SomethingHappened

    MessageBox.Show("worked")

    End Sub


  • Creating Events