DotNet Listview with checkboxes: Selecting multiple items toggles the checked states


#1

Using a DotNet Listview with checkboxes enabled, I noticed that when you select multiple items at once, it toggles the checkbox of some of the items, which is a very bad, bad thing.

Has anyone else noticed this and/or solved it? Thanks!


#2

I’ve refined my understanding of the problem a little further, and here’s what can be done in order to reproduce the proclem with your own listviews:

The Listview must have multiple columns, and the .fullRowSelect property must be set to true. Turn off all the checkboxes, and start shift-clicking on random items in any column except the first. The problem does not exist if you only do your selecting in the first column, however that’s quite a limitation to impose on the user.


#3

Sounds like a bit of a bug to me. Do you have a simple script that shows the problem. I could send it to the powers that be at AD for a look.


#4

rollout ListviewBugTest "" ( 
 
 dotNetControl lv "System.Windows.Forms.ListView" width:380 height:280 align:#center pos:[10,10]
 
 on ListviewBugTest open do ( 
  
  -- Setup the listview
  lv.View = (dotNetClass "System.Windows.Forms.View").Details  
  lv.fullRowSelect = true  
  lv.checkBoxes=true
  
  -- Add Column Headers
  for i =1 to 4 do lv.Columns.add ("Column "+i as string)
  
  -- Add items to listview
  for x=1 to 5 do (
   local newItem = dotNetObject "System.Windows.Forms.ListViewItem" "Col. 1"  
   for whichCol =2 to lv.Columns.count do newItem.SubItems.Add ("Col. " + whichCol as string)
   lv.items.add newItem    
  )  
 ) 
)
createDialog ListviewBugTest width:400 height:300

Thanks!


#5

Confrimed, I’m seeing the same problems.


#6

Don’t bother informing AD… it’s Bill Gates you need to talk to…

Same UI item build in Visual Basic… does some unexpected things when clickin on it?

How’s Python’s checked Listview react?


#7

OK, I already did, but I sent a letter bomb to Bill. When he opens it a bunch of PC fairies jump out and format all the hard drives in Bills posession.


#8

I came across this problem in C#, when using a ListView with FullRowSelect property set to true. You can workaround this by:

  1. Setting FullRowSelect property to false.

or

  1. Bypassing some events like MouseDown after you invoke appropriate events as if they are done (like clicked) in the first column.

So if you multiple select ListView nodes in the first column, it always works.

I haven’t tried #2 but it “could” be done.

Light


#9

Yeah… This bug has been around since the start of dotnet… A thread from Nov, 2002 complaining about the same mis-functionallity…

"That is known issue of the ListView control. It is because if multiple
items were selected, we were firing onItemCheck for each item. But, since
we were creating a temp variable for ItemCheckEventArgs inside the foreach
loop, any change to this variable made by the onItemCheck event handler
were being discarded. "

http://groups.google.com/group/microsoft.public.dotnet.languages.vb/browse_thread/thread/16336d722f168811/441abc77dd9ec4af?hl=en&lnk=st&q=dotnet+ListView++FullRowSelect+bug#441abc77dd9ec4af

They then recommend subclassing the control and programming it yourself…

Humm… I thought the point of .net framework was I didn’t need to program down to every little click and mouse move… I guess I could invoke XVGA mode and set pixels that look like checkboxs with direct memory access calls as well… :slight_smile:


#10

Wow… I sure stepped into it this time. Thanks everyone.


#11

Ok, I seem to have stumbled upon a workable solution using two additional event handlers.

I used the ItemSelectionChanged event to record the correct checkbox states of the selected items before DotNet introduces the error, and then I used the MouseUp event to reset the checkboxes to their correct recorded states after the errors are introduced.

Here’s the revised code:


rollout ListviewBugTest "" ( 
 
 dotNetControl lv "System.Windows.Forms.ListView" width:380 height:280 align:#center pos:[10,10]
 
 local selNums, checkStates
 
 on lv MouseUp e do (
  for x = 1 to selNums.count do lv.items.item[selNums[x]].checked=checkStates[x] -- correct the checkboxes
  selNums=#(); checkStates=#() -- clear the record
 )
 
 on lv ItemSelectionChanged e do (-- record the states of the checkboxes so we can correct them at MouseUp	
  selNums=for x=0 to lv.selectedIndices.count-1 collect lv.selectedIndices.item[x]
  checkStates=for x=1 to selNums.count collect lv.items.item[selNums[x]].checked	
 ) 
 
 on ListviewBugTest open do ( 
  
  -- Setup the listview
  lv.View = (dotNetClass "System.Windows.Forms.View").Details  
  lv.fullRowSelect = true  
  lv.checkBoxes=true
  
  -- Add Column Headers
  for i =1 to 4 do lv.Columns.add ("Column "+i as string)
  
  -- Add items to listview
  for x=1 to 5 do (
   local newItem = dotNetObject "System.Windows.Forms.ListViewItem" "Col. 1"  
   for whichCol =2 to lv.Columns.count do newItem.SubItems.Add ("Col. " + whichCol as string)
   lv.items.add newItem	
  )  
 ) 
)
createDialog ListviewBugTest width:400 height:300
 

#12

Excellent… I don’t need it right now, but I’m sure I will… I’m gonna sqirrel this little code snippit away…

Thanks for sharing…


#13

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.