Re: enable/disable buttons based on ListView selection

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Linda Liu [MSFT] wrote:
Hi Brandon,

When a ListView's View property is set to List, LargeIcon, or SmallIcon, the bound of an item in it limited to the item text. When you click on one item in a ListView, you should see a dotted line around the item text, and this is the bound of the item.

I like the List view because I didn't want the items' text to wrap like it does using Large/SmallIcon view.


Only when you click inside the bound of an item, this item can be selected and the corresponding events, such as SelectedIndexChanged, ItemSelectionChanged events can be raised.

Well it doesn't make sense that even though I'm not clicking on the text (but still within the ListView bounds) that a click event is not being generated. Why is the item and not the listview itself generating the event (or so it seems)? If I click in the listview (with no item previously selected) but not on an item in the list nothing gets selected but yet if I click in the same spot after something is selected that item stays selected: it isn't consistent in my opinion. It is consistent from the point of view of no event being generated to change the selection state but not from the point of view not having anything selected if I don't click on an item.

In fact, the proximity to which I have to be to the item to get it be selected w/o actually clicking on the item itself is not the same proximity that I need to be within when I click to de-select the item: I have to click further away from an item to de-select it so that's another inconsistency.

If the ListView is generating the events then I shouldn't have to always click on an item in order for a click event to be generated. Not clicking on the item would show SelectedItems.Count to be = 0 and clicking on an item would show SelectedItems.Count to be = 1, simple.

I'll try the ListBox. Maybe it will be more sane.


This behavior of ListView is by design. If you don't like this limited item bound, you may use ListBox instead. You can handle the SelectedIndexChanged event of the ListBox to get notified when different item is selected in the ListBox.

Hope this helps.
If you have any concerns, please feel free to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 1 business day is acceptable. Please note that each follow up response may take approximately 2 business days as the support professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations that require urgent, real-time or phone-based interactions or complex project analysis and dump analysis issues. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

.


Quantcast