views:

113

answers:

1

I've just added one of the new (MFC Feature Pack) CVSListBox controls to a project. The list of items in the control is tracked by some other objects in my application, so I need to take lots of notifications from the list-box when anything changes so that I can update other stuff. For those that don't know the control, there is a button bar which offers basic add/delete/reorder functionality.

The CVSListBox control offers overridable virtual functions for things like adding or renaming items, and changing their order - all this works nicely.

However, for deleting items, the only override is OnBeforeRemoveItem, which is called BEFORE an item is removed, and from which one has to return TRUE/FALSE to permit the remove. Once the remove has occurred, there's no specific notification.

What's the best way to get notification AFTER a remove?

Obviously it's possible to hack something horrible here, in that there will be a selection-changed event after a remove, and it would be possible to hold a flag from the before-remove to say that the next selection-changed is special. But I feel like I'm missing something cleaner and more obvious. Any suggestions?

A: 

Assuming that the item will truly be removed every time, you could either:

  • Do the handling in the OnBeforeRemoveItem override as if the item was already removed
  • Raise your own OnAfterItemRemoved event
  • See if you can get a handle on the underlying list control (whatever it may be) and hook one of its events
Aidan Ryan