Last control on focus

G

glerner

Hi,
I want to know which control the focus was on last. I have several
listview controls on my form and when I click on "Update" button,
depending on where the focus was I want to perform different tasks.

I tried Focused property on each listview control but unfortunately by
the time the button is clicked the focus is no longer on the listview
controls because focus is now on the button control.

Thanks,
Glenn
 
T

Tim Jarvis

glerner said:
Hi,
I want to know which control the focus was on last. I have several
listview controls on my form and when I click on "Update" button,
depending on where the focus was I want to perform different tasks.

I tried Focused property on each listview control but unfortunately by
the time the button is clicked the focus is no longer on the listview
controls because focus is now on the button control.

Thanks,
Glenn



----------------------------------------------------------

----------------------------------------------------------
color]

there is probably a better way than this, but quickly of the top of my
head you could write an event handler for the leave event and attach it
to all the form controls and set a flag when the control lose's focus,
the flag would contain the last one. (the flag could be an enumerated
type, which you then switch from)

A bit of a sledgehammer approach, but could be a plan B if you don't
find a better way.

Rgds Tim.
 
A

Andrija

use same onfocus event handler for all listviews, and when any of them gets
focus, store a
value (listview name or whatever) into a variable. when updating, use switch
statement to update appropriate listview.
Even easier is to make an array of controls (ListView[] myListViews=new
ListView[x])
 

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