By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,231 Members | 1,707 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,231 IT Pros & Developers. It's quick & easy.

How to get control identification from (Sender as Object)

P: n/a
Hi,

I have this event that is performed by three different controls, how can
I know (from sender object) wich control is used to trigger the event?

Private Sub HighlightSelectedRow(ByVal sender As Object, ByVal e As
System.EventArgs) Handles tbxAmount.Click, lblID.Click, lblExpense.Click

Dim ctlControl As System.Type
ctlControl = sender.GetType

'???
Select Case ctlControl
'???
End Select

End Sub
Thanks

Marty
Jul 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
You can use TypeOf and CType.

If TypeOf sender Is Label Then
Dim lbl As Label = CType(sender, Label)
Select Case lbl.Name
Case Is = "lblID"
' do something
Case Is = "lblExpense"
' do something
End Select
ElseIf TypeOf sender Is TextBox Then
Dim txt As TextBox = CType(sender, TextBox)
' do something
End If

"Marty" <xm******@hotmail.com> wrote in message
news:tI**************@fe51.usenetserver.com...
Hi,

I have this event that is performed by three different controls, how can I
know (from sender object) wich control is used to trigger the event?

Private Sub HighlightSelectedRow(ByVal sender As Object, ByVal e As
System.EventArgs) Handles tbxAmount.Click, lblID.Click, lblExpense.Click

Dim ctlControl As System.Type
ctlControl = sender.GetType

'???
Select Case ctlControl
'???
End Select

End Sub
Thanks

Marty

Jul 21 '05 #2

P: n/a
Wonderful, thanks you!

Marty

Jared wrote:
You can use TypeOf and CType.

If TypeOf sender Is Label Then
Dim lbl As Label = CType(sender, Label)
Select Case lbl.Name
Case Is = "lblID"
' do something
Case Is = "lblExpense"
' do something
End Select
ElseIf TypeOf sender Is TextBox Then
Dim txt As TextBox = CType(sender, TextBox)
' do something
End If

"Marty" <xm******@hotmail.com> wrote in message
news:tI**************@fe51.usenetserver.com...
Hi,

I have this event that is performed by three different controls, how can I
know (from sender object) wich control is used to trigger the event?

Private Sub HighlightSelectedRow(ByVal sender As Object, ByVal e As
System.EventArgs) Handles tbxAmount.Click, lblID.Click, lblExpense.Click

Dim ctlControl As System.Type
ctlControl = sender.GetType

'???
Select Case ctlControl
'???
End Select

End Sub
Thanks

Marty


Jul 21 '05 #3

P: n/a
Marty,
In addition to Jared,

Keep in mind that you do not have to know the type when the member is
inheritted from control.

They have by instance all name, text, click etc.

Cor
Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.