ListView vs ListBox

  • Thread starter Thread starter Joe Cool
  • Start date Start date
J

Joe Cool

I have an app I am working on where I was using a ListBox to display a
list of items on a form. I decided I'd rather the control be a
ListView. But something that worked on the ListBox doesn't work the
same way as a ListView and I cannot find a way to overcome it.

The ListBox had a context menu and the form had a couple of command
buttons that operated on the selected item in the list. The context
menu items use the same click event as the command buttons. The
context menu items and command buttons are only enabled if an item was
selected. After clicking on one of the context menu items or the
corresponding command button, and the action in the click event is
processed, if the item still existed in the list, it was still
selected.

However, the ListView acts differently.

Remember, the context menu items link to the same click event handlers
as the buttons.

If you perform an action via the context menu, the item(s) selected
remain selected. If you perform the action via the command button, all
items are de-selected. EVEN THOUGH THE SELECTED PROPERTY IS STILL
TRUE!!!

Setting the Item's Selected property does not help.

I hope someone with more experiance than I can help!!!

TIA.
 
I have an app I am working on where I was using a ListBox to display a
list of items on a form. I decided I'd rather the control be a
ListView. But something that worked on the ListBox doesn't work the
same way as a ListView and I cannot find a way to overcome it.

The ListBox had a context menu and the form had a couple of command
buttons that operated on the selected item in the list. The context
menu items use the same click event as the command buttons. The
context menu items and command buttons are only enabled if an item was
selected. After clicking on one of the context menu items or the
corresponding command button, and the action in the click event is
processed, if the item still existed in the list, it was still
selected.

However, the ListView acts differently.

Remember, the context menu items link to the same click event handlers
as the buttons.

If you perform an action via the context menu, the item(s) selected
remain selected. If you perform the action via the command button, all
items are de-selected. EVEN THOUGH THE SELECTED PROPERTY IS STILL
TRUE!!!

Setting the Item's Selected property does not help.

I hope someone with more experiance than I can help!!!

TIA.

Crap, I do this a lot. Ten minutes after posting a "help me" message,
I figure it out. All I had to do was select the ListView at the end of
the menu/button click event.
 
If you perform an action via the context menu, the item(s) selected
remain selected. If you perform the action via the command button, all
items are de-selected. EVEN THOUGH THE SELECTED PROPERTY IS STILL
TRUE!!!

Setting the Item's Selected property does not help.

I hope someone with more experiance than I can help!!!

They aren't deselected, the selection highlight just isn't painted unless
the ListView has the focus. Tabbing a few times until the ListView has
focus again will prove this to be true.

There's a AlwaysShowSelected or HideSelection or something like that sort of
property to fix this.
 
Back
Top