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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TListView Events: OnClick and OnDragDrop 1

Status
Not open for further replies.

Glenn9999

Programmer
Jun 19, 2004
2,311
0
36
US
I'm working on a program with a form that has a TListView. I got most everything working in it except the edit function. What I'm wanting is to be able to use some other controls to edit the data in the TListView and then if the user clicks away on the TListView to make the changes.

Problem is that I have the edit function tied to OnClick and OnClick fires when I do a drag/drop operation. This causes an edit on the record that is moved, which is NOT what I'm looking to do.

If you need a visual representation of what I'm trying to do, look at the bookmarks/Show all Bookmarks option of Firefox 4.01 where individual URLs occur.

Any ideas?

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
You could set a variable when the user starts the drag operation and detect that in your OnClick. Or the drag operation could disable the OnClick event handler altogether and then reassign it when the drag operation ends.
 
Here's a code sample of what I do, like DjangMan mentioned above...

Code:
  private
    Dragging: Bool;

/////////////////////////////////

procedure TForm1.ListView1StartDrag(Sender: TObject; var DragObject: TDragObject);
begin
  Dragging:= True;
end;

procedure TForm1.ListView1EndDrag(Sender, Target: TObject; X, Y: Integer);
begin
  Dragging:= False;
end;

procedure TForm1.ListView1DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);
begin
  Dragging:= True;
end;

procedure TForm1.ListView1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
  Dragging:= False;
end;

procedure TForm1.ListView1Click(Sender: TObject);
begin
  if not Dragging then begin

    //Your code here

  end;
end;


JD Solutions
 
Thanks for the suggestions.

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
Another question. Trying this to select a TListView item:

Code:
Listview1.SetFocus;
ListView1.Items[0].Selected := true;

But it's not working at all. Any ideas on how to solve this?

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
It was a code bug in the delphi code. Compiled with TD2006 and worked right out of the gate. Unfortunately can't use it though for this project I'm working on.

I worked around the problem.

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top