Hello Experts... I'm working with a TListView that has checkboxes enabled and in "vsReport" style. My goal is to be able to double-click on any item and have that item "swap places" with whatever item is in the top of the ListView (ie. Item). Googling around, I found some code on this website that I'm using:
It outlines an "ExchangeItems" procedure that looked to be just what I needed. I added only a few lines to it for my specific needs . Normally it would swap Item(i) and Item[j]... I wanted it to swap Item and Item[j]. And also to correctly swap the value of the "checked" property too. Here's my code:
procedure TForm1.ExchangeItems(lv: TListView; const j: Integer);
Item0CheckedState, ItemJCheckedState : Boolean;
tempLI := TListItem.Create(lv.Items);
end; // procedure ExchangeItems
Simple enough i thought... and seemed logically sound. I tried a small test - I added only 3 items to my ListView: Thing0, Thing1, and Thing2. I put a checkmark in the middle item Thing1. and left the other two unchecked. Then I double-clicked on the bottom Thing2 item. The procedure does indeed "swap" the two items and their corresponding "checked" values correctly, but it unexpectedly and unwantedly turns the Checked setting of item Thing1 (...which was TRUE) to FALSE. I put tracing statements after every line of the code in that procedure to find out where this was occurring, and it appears the culprit is this line:
Immediately after this line, the "checked" value of Thing1 got switched to FALSE, for some reason. This one is driving me bonkers trying to figure out. Does anyone have some insight please?