Hi Rhett,
If it's by design that the ListBox behaves differently to the ListView (and
TreeView) then the design is flawed IMO. How can a developer rely on a
specific event order if it changes depending on which controls are being
used?
In your 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
I think the [// step2:click ListView item] is where
listView1_SelectedIndexChanged occurs before listBox1_Leave is a problem.
I'm not the only one at my company that thinks so.
The use case I need a solution for is as follows:
A control (a ListView or a TreeView) represents the view on a table. Then,
in the same dialog, the ListBox or other control represents the details of
the SelectedItem in the TreeView/ListView.
Like this:
// Manager with a list of items (Item 1 is selected)
ListView ListBox (or other control)
____________ ________________
| Item 1 | | Contents of Item 1 |
| Item 2 | | Contents of Item 1 |
| | | Contents of Item 1 |
____________ ________________
Now, the ListBox contents needs to be refreshed based on the ListView
selection... either Item 1 or Item 2 in this case.
If I now select Item 2 the SelectedItemChanged event fires immediately!!!
Thus I have no context or hook to commit or validate the data in the ListBox
since the SelectedItem changes in the ListView even before the Leave,
Validating and Validated events fire in the ListBox!
The work around I need is some context to commit (and/or validate) the data
BEFORE the SelectedIndex changes in the ListView. Basically, with the
current event order this is clearly not possible, yet if the ListView was
another ListBox or one of a number of other controls (including 3rd party
controls) that DO behave correctly, it all works fine. Why the ListView and
TreeView have to be different is quite frustrating.
I still can't see how this would be the expected behavior for the ListView
(and TreeView). Doesn't it feel wrong to you that the SelectedItemChanged
event fires at the response to a mouse click even before the control has
focus? Here we have a control receiving and responding to user input when
clients listening to the Enter and Leave events of the ListBox still would
assume that the ListBox has focus. Meanwhile the user is off interacting
with another control and manipulating its data.
Regards,
Wayne.
Rhett Gong said:
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--KillFocus
ListBox--SetFocus
ListBox--SelectChanged
ListControl--SelectChanged
ListControl--SelectChanged
ListControl--SelectChanged
ListBox--KillFocus
ListControl--SetFocus
//-------------------------------------------------------
You can see that the MFC application behaves the same way as DotNet.
It is by design.
Can you detailed your request so that we can try to get a workaround for
you!
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.