Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

keep selected items on listview mouse-click 1

Status
Not open for further replies.

xartas

Programmer
Aug 20, 2001
26
ES
Billy provided a solution for listboxes. I didnt worked it out for such components since i'm not currently handling 'em. Only sure the solution is not working for ListViews for the MouseUp event does not occur when i was expecting it to come up.

The problem arises when one wants a Windows Explorer like behaviour in a ListView and realizes ListView items get deselected just at mouse-click entering (which shoul occur on second mouse-clicking).

Can anyone give me a helping hand (not very longwinded if possible) with this problem?????
 
The way I see it, you have 2 options. One is to inherit the tListView and change the MouseClick routine, or secondly, more simply... just

private
{ Private declarations }
// Add a private declaration for a global var:
strSelectedItems: string;
...

// add a listview enter routine (onEnter event)
procedure TForm1.ListView1Enter(Sender: TObject);
var
i : integer;
begin
strSelectedItems := '';
for i:=0 to ListView1.SelCount-1 do
if ListView1.Items.Selected then
strSelectedItems := strSelectedItems + '1'
else
strSelectedItems := strSelectedItems + '0';
end;

// then add a Click routine (onMouseClick event)
procedure TForm1.ListView1Click(Sender: TObject);
var
i : integer;
begin
if (strSelectedItems <> '') and (ListView1.Items.Count>=length(strSelectedItems)) then
for i:=0 to length(strSelectedItems)-1 do
ListView1.Items.Selected := (strSelectedItems[i+1]='1');
strSelectedItems := '';
end;

Hey presto - done and dusted. I even tested it!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top