Re: Event Order by Wayne
Wayne
Tue Nov 11 05:57:01 CST 2003
Hi Claes,
Thanks for the response, but I think you missed the point. I'm not
insinuating any relationship between events in different controls. I do,
however, believe the order of events is questionable in this case.
If control A has focus, and control B (a ListView) is clicked on, it seems
very wrong that the ListView's SelectedIndexChanged event would fire before:
a) The Leave event of control A, and any subsequent validation events for
control A
b) The ListView's own Enter event!
My way of thinking, as twisted as it may be, is that for a control to react
to a mouse click and fire SelectedIndexChanged it needs to have focus. I
read somewhere in the Windows API 101 that that's the way it works. The
window with focus receives the WM_ guys and it's WndProc deals with the ones
it wants and ignores the ones it doesn't. In this case it receives a mouse
click and changes the selected item. Given that the ListView must have focus
to respond to a mouse click, then it must have entered focus at some point,
which also means that the control with previous focus must have also lost
focus and been validated (if applicable). Now, why does the
SelectedIndexChanged event fire before a and b above?
This behavior is not the same for all other controls. e.g. the ListBox
control's SelectedIndexChanged event fires AFTER a and b above.
To me this event order is wrong and given the fact it is the way I would
expect for most controls, but out of order for the ListView and TreeView, it
seems something is not right.
In the use case I have, the contents of control A depends on the
SelectedIndex in the ListView. How am I to commit the data in control A, for
the index designated by the ListView's SelectedIndex when that SelectedIndex
changes even before I've had a chance to validate the contents of control
A?? You can't tell me that is the correct behavior.
Regards,
Wayne.
"Claes Bergefall" <claes.bergefall.nospam@frontec.se> wrote in message
news:%23PtWpJDqDHA.1324@TK2MSFTNGP09.phx.gbl...
> See inline
>
> "Wayne Hartell" <whar@haestad.com> wrote in message
> news:uMtVq2$pDHA.2000@TK2MSFTNGP12.phx.gbl...
> > Hi there,
> >
> > I was wondering how the SelectedIndexChanged event can fire in a
ListView
> > control before the Leave event fires in the previous control that is
> losing
>
> I don't see anything wrong with this. The SelectedIndexChanged event is
> in no way dependent on any other control.
>
> The SelectedIndexChanged event fires when you change the currently
> selected item in the listview, any other behaviour would clearly be wrong.
> It has nothing to do with the Leave event.
>
>
> > focus? Is this the designed behavior? I really need to be able to handle
> the
> > Leave event first and seeing validation events fire AFTER leave, it
seems
> > that no events should fire in the list view until after the Leave even
> (and
> > validation events if not suppressed).
>
> Validation events fires after the Leave event. This is by design and is
> documented in MSDN. SelectedIndexChanged is not a validation event.
>
> >
> > Kind Regards,
> > Wayne Hartell
> >
>
> /claes
>
>