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
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).

Kind Regards,
Wayne Hartell

Re: Event Order by Wayne

Wayne
Mon Nov 10 21:00:14 CST 2003

Further to this I set up a form with a ListView and a ListBox and can easily
demonstrate the difference in event order between the two.

The ListBox behaves as expected, with the SelectedIndexChanged occuring
after the Enter event. Not so for the ListView. The SelectedIndexChanged
events fire event before the Leave event for the ListBox, and sometimes more
than once!

I can provide a sample project if needed. This is under v1.1 of the
framework.

listView1_Enter
listView1_Leave
listView1_Validating
listView1_Validated
listBox1_Enter
listBox1_SelectedIndexChanged
listView1_SelectedIndexChanged
listBox1_Leave
listBox1_Validating
listBox1_Validated
listView1_Enter
listView1_Leave
listView1_Validating
listView1_Validated
listBox1_Enter
listBox1_SelectedIndexChanged
listView1_SelectedIndexChanged
listView1_SelectedIndexChanged
listBox1_Leave
listBox1_Validating
listBox1_Validated
listView1_Enter

Wayne



"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
> 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).
>
> Kind Regards,
> Wayne Hartell
>
>



Re: Event Order by Wayne

Wayne
Mon Nov 10 22:30:51 CST 2003

Just one more piece of information. The TreeView control also seems to
suffer the same flaw. The AfterSelect event fires before the Enter event for
the control, thus not providing any hook/context for the programmer to do
something in the Leave event of the previous control.

Please tell me there is a solution.

Wayne.

"Wayne Hartell" <whar@haestad.com> wrote in message
news:emlDw$$pDHA.488@tk2msftngp13.phx.gbl...
> Further to this I set up a form with a ListView and a ListBox and can
easily
> demonstrate the difference in event order between the two.
>
> The ListBox behaves as expected, with the SelectedIndexChanged occuring
> after the Enter event. Not so for the ListView. The SelectedIndexChanged
> events fire event before the Leave event for the ListBox, and sometimes
more
> than once!
>
> I can provide a sample project if needed. This is under v1.1 of the
> framework.
>
> listView1_Enter
> listView1_Leave
> listView1_Validating
> listView1_Validated
> listBox1_Enter
> listBox1_SelectedIndexChanged
> listView1_SelectedIndexChanged
> listBox1_Leave
> listBox1_Validating
> listBox1_Validated
> listView1_Enter
> listView1_Leave
> listView1_Validating
> listView1_Validated
> listBox1_Enter
> listBox1_SelectedIndexChanged
> listView1_SelectedIndexChanged
> listView1_SelectedIndexChanged
> listBox1_Leave
> listBox1_Validating
> listBox1_Validated
> listView1_Enter
>
> Wayne
>
>
>
> "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
> > 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).
> >
> > Kind Regards,
> > Wayne Hartell
> >
> >
>
>



Re: Event Order by Claes

Claes
Tue Nov 11 03:01:39 CST 2003

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



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
>
>



Re: Event Order by v-raygon

v-raygon
Tue Nov 11 06:37:37 CST 2003

Hi Wayne:
From your event log, the ListBox behaves correctly.
Do you mean that the SelectedIndexChanged occurs after the Leave event
in ListView?
If yes,please send me your sample project for a test.
Just remove the online from my email address. Thanks!


Best regards,

Rhett Gong [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.


Re: Event Order by Wayne

Wayne
Tue Nov 11 07:15:20 CST 2003

Hi Rhett,

Yes, the ListBox behaves correctly. I don't think the ListView does though;
it behaves differently to the ListBox.

The SelectedIndexChanged fires in the ListView even before the Leave (and
validation) for the ListBox and before Enter for the ListView.

I can send sample application if needed.

Thanks,
Wayne.

"Rhett Gong" <v-raygon@online.microsoft.com> wrote in message
news:aZsBmCFqDHA.2048@cpmsftngxa06.phx.gbl...
> Hi Wayne:
> From your event log, the ListBox behaves correctly.
> Do you mean that the SelectedIndexChanged occurs after the Leave event
> in ListView?
> If yes,please send me your sample project for a test.
> Just remove the online from my email address. Thanks!
>
>
> Best regards,
>
> Rhett Gong [MSFT]
> Microsoft Online Partner Support
> Get Secure! - www.microsoft.com/security
>
> This posting is provided "AS IS" with no warranties and confers no rights.
>



Re: Event Order by v-raygon

v-raygon
Tue Nov 11 23:51:02 CST 2003

Hi Wayne:
Here is my event log:
//------------------------------------------------------
listView1_Enter
// step1:Click ListBox item
listView1_Leave
listView1_Validating
listView1_Validated
listBox1_Enter
listBox1_SelectedIndexChanged

// step2:click ListView item
listView1_SelectedIndexChanged
listBox1_Leave
listBox1_Validating
listBox1_Validated
listView1_Enter

// step3:Click ListBox item
listView1_Leave
listView1_Validating
listView1_Validated
listBox1_Enter
listBox1_SelectedIndexChanged

// step3:Click ListView item
// notice here is different , I clicked the same item as before.
listBox1_Leave
listBox1_Validating
listBox1_Validated
listView1_Enter
//-------------------------------------------------------

I write a program in MFC, the log is listed below:
//-------------------------------------------------------
ListControl--SelectChanged
ListControl--SetFocus
ListControl--SelectChanged
ListControl--SelectChanged
ListControl--SelectChanged
ListControl--KillFocus
ListBox--SetFocus
ListBox--SelectChanged
ListBox--KillFocus
ListControl--SetFocus
ListControl