DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Wed, 22 Aug 2007 22:52:10 -0700,    posted on: microsoft.public.dotnet.languages.vb        back       

Thread Index
  1    unknown
          2    Johnny Jrgensen


ListView prevent deselect   
I'm using a ListView and if the user doesn't click on an item any
previous item is deselected.  I cannot allow an empty selection, so
how can I prevent an item from being deselected if no other item is
going to be selected?

Thanks

--
Brent
Date:Wed, 22 Aug 2007 22:52:10 -0700   Author:  

Re: ListView prevent deselect   
Some ideas come to mind:

The second easiest:

You save the selection in the SelectionChanged Event and in the Mouse events 
you check if there is a selection or not. If not then you "restore" the 
previously saved selection...

The hardest:

You subclass the Listview to intercept the Windows messages to the control. 
When a mousedown event is fired, you check the mouse coordinates to see if 
there is an item under the cursor. If not, you don't pass on the message to 
the control.

The wackiest:

You calculate how much of the Listview that is NOT occupied by items: 
ListView Height - (Header Height + Item Count * Item Height) and then you 
position a label or a textbox - with no border and same backcolor as the 
Listview - over that area. That way, the dummy control gets the mouse 
events - not the listbox. Don't forget to take into consideration the height 
of a horizontal scrollbar if one is present...

And by far the easiest:

You allow no selection but tell your user when he/she tries to leave the 
form that a selection has to be made. You cancel the form close and return 
focus to the listview

In my opinion, the deselection of items when you click on the non-item area 
ought to be up to the programmer by setting a property, but as usual, 
Microsoft is not making it easy for us... :-)

Cheers and good luck,
Johnny J.




 wrote in message 
news:1187848330.102491.234000@q3g2000prf.googlegroups.com...

> I'm using a ListView and if the user doesn't click on an item any
> previous item is deselected.  I cannot allow an empty selection, so
> how can I prevent an item from being deselected if no other item is
> going to be selected?
>
> Thanks
>
> --
> Brent
> 
Date:Thu, 23 Aug 2007 09:32:28 +0200   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us