control name

G

Guest

I want to dynamically get the control from the event being executed at a
particular time. For example, lets say I have the following event.
combobox1_SelectedIndexChanged((ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArgs) Handles combobox1.SelectedIndexChanged

I don't want to just specify combobox1. I need to dynamically get the
control from the eventsender or some other method so I can write a generic
function used for any control without having to specify the actual controls
like comboBox1 or ComboBox2.

I would really appreciate someone telling me how to do it.

Thanks
 
G

Guest

Nevermind, I figured out I could just say the following:

dim x as object
x=eventsender

I was trying to use the eventsender.gettype.SOMETHING and didn't realize
just setting x = to eventsender would give me everything I was after.

Thanks
 
R

rowe_newsgroups

Nevermind, I figured out I could just say the following:

dim x as object
x=eventsender

I was trying to use the eventsender.gettype.SOMETHING and didn't realize
just setting x = to eventsender would give me everything I was after.

Thanks

Note that you can also cast the sender into a certain type instead of
just leaving it as an object:

i.e.

private sub combobox_SomeEvent(sender as object, e as eventargs)
if (sender is Combobox)
Dim cbo as ComboBox = DirectCast(sender, combobox)
' Do combobox specific stuff here
else if (sender is TextBox)
Dim tb as TextBox = DirectCast(sender, textbox)
' Do textbox specific stuff here
end if
end sub

Thanks,

Seth Rowe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top