Active Control Name via Button.Click

R

Randy

I have a form on which various controls are added dynamically
depending on actions of the user. One of these actions allows the
user to click a delete button that will remove various other
controls. I was trying to accomplish this Click procedure by
capturing the active contold using activecontrol.name and then
removing it, but as soon as I click on the Delete button, the active
controls changes to the delete button, not the control that I want to
remove. Here is the code:

Private Sub btnDelCtl_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnDelCtl.Click
Dim ctlThisCtl As String = ActiveControl.Name
MessageBox.Show(ctlThisCtl) 'to confirm deletion of the
correct control
End Sub

When I run this, the value of ctlThisCtl is "btnDelCtl", which is not
what I want to delete. Anybody have a suggestion as to how I can
capture the control that was active immediately prior to clicking the
btnDelCtl button?

Thanks,
Randy
 
R

rowe_newsgroups

I have a form on which various controls are added dynamically
depending on actions of the user. One of these actions allows the
user to click a delete button that will remove various other
controls. I was trying to accomplish this Click procedure by
capturing the active contold using activecontrol.name and then
removing it, but as soon as I click on the Delete button, the active
controls changes to the delete button, not the control that I want to
remove. Here is the code:

Private Sub btnDelCtl_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnDelCtl.Click
Dim ctlThisCtl As String = ActiveControl.Name
MessageBox.Show(ctlThisCtl) 'to confirm deletion of the
correct control
End Sub

When I run this, the value of ctlThisCtl is "btnDelCtl", which is not
what I want to delete. Anybody have a suggestion as to how I can
capture the control that was active immediately prior to clicking the
btnDelCtl button?

Thanks,
Randy

Perhaps a search in the archives would help:

http://groups.google.com/group/micr...&q=last+active+control&qt_g=Search+this+group

If you can't find something that works, let me know and I'll take a
better look.

Thanks,

Seth Rowe
 
R

Randy

Thanks, Seth. I had done numerous searches prior my post, but not on
"last" active control. It was easy once I found a post that suggested
using LostFocus.

Thanks for the suggestion!

Randy
 

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