How to get control identification from (Sender as Object)  
Author Message
spfeltman





PostPosted: Sat Oct 09 13:09:24 CDT 2004 Top

Visual Basic [VB] >> How to get control identification from (Sender as Object) 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

Visual Studio242  
 
 
Jared





PostPosted: Sat Oct 09 13:09:24 CDT 2004 Top

Visual Basic [VB] >> How to get control identification from (Sender as Object) 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" <EMail@HideDomain.com> wrote in message
news:tIV9d.298$EMail@HideDomain.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
>
>


 
 
Marty





PostPosted: Sat Oct 09 13:27:36 CDT 2004 Top

Visual Basic [VB] >> How to get control identification from (Sender as Object) 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" <EMail@HideDomain.com> wrote in message
> news:tIV9d.298$EMail@HideDomain.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
>>
>>
>
>
>


 
 
Cor





PostPosted: Sun Oct 10 02:35:30 CDT 2004 Top

Visual Basic [VB] >> How to get control identification from (Sender as Object) 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