Bizarre behavior with listview StartLabelEdit and multiselecting

willjones

Registered User.
Local time
Today, 16:51
Joined
Mar 24, 2007
Messages
13
This is driving me crazy! I have some code that has a list of items in a listview. When I right click it shows a pop-up right click menu with a macro. Then I select an item in the list that says Rename. After ensuring a single element is selected the StartLabelEdit method is called on my list view. Then I can begin editing. Normally this works fine. However, if I first double click a list item. Then I enter my double click list view event handler and from there I open a form. Later if I close that form and then try right-clicking and selecting rename. This time after StartLabelEdit is called, the BeforeLabelEdit event is never called. The whole selected line blinks momentarily and then wherever my cursor is at that moment every item between it and the originally selected item becomes selected. If I move my mouse around the selection changes to be between the originally selected item and the one my mouse is over as it moves. It's as though I had clicked the left mouse button down but didn't let go of it and then started moving the mouse around. If I left click and release again it seems to get out of this mode, but I am still not able to ever manually invoke the StartLabelEdit method after this point. If I close the form and re-open it, it works fine. (I've tried calling refresh on the list view but this had no effect.)

Here's the really weird part. If instead of double-clicking to open a form, I right click and select a menu option to call the exact samed double click event method. Everything works fine as you would expect. Then I tried another test. I made the double click method call another method to open the form. When I did this and tried the same alternate way of opening a form, it did not work and the same original error occurred again. This weird behavior is bizarre and I have no real idea how to troubleshoot it any further.
:mad:

Has anyone ever seen or heard of something like this where StartLabelEdit goes haywire? Please help me if you can.

Thanks...
-Will
 
Time Delayed call solved my problem

I finally found a way to solve this problem.

An easy way to re-create this:
Populate a listview control with some values. Set label editing mode to Manual. Put MsgBox "Hello",vbOkOnly in the listview_DblClick event handler. Now put a call to listview.StartLabelEdit in the listview_keydown event handler. Run this. Select a line in the listview and press a key. Verify that it opens for label editing. Now click on another row only this time double click it. Click ok on the message box. Then click on a row in the list view. Press a key to cause the keydown event to fire and call StartLabelEdit. The call should fail this time and the currently selected row will not be opened for editing.

To correct this problem if you use the Form_Timer and initiate a time delayed call from the dbl click event for about 150 milliseconds. And then after this time has elapsed show the message box. Everything works correctly as you would expect. Originally I attempted a time delayed call, but with only 1 millisecond and it didn't work. When I pushed the length of the time delay out a bit more it began to work correctly. Strange huh? I'm just glad I finally figured it out and got it working. :)
 

Users who are viewing this thread

Back
Top Bottom