Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Drag and drop problem

jamesb800jamesb800 Member Posts: 105
Hello all,

I am using this code to drag and drop from a listbox to a richedit.
It works when the listbox is on the same form as the richedit but not
when the listbox is on a different form:
[code]
procedure TfrmMain.RE1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
// fake mouse click at current cursor position
mouse_event( MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 );
mouse_event( MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 );
// allow control to handle the mouse messages and put the caret at that
// position.
Application.ProcessMessages;
// transfer the text
With Source as TListbox Do
If ItemIndex >= 0 Then
RE1.seltext := '['+Items[itemindex]+']';
end;

procedure TfrmMain.RE1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept:= Source is TListbox;
end;
[/code]

How can I get it to work?

Thanks in advance,
James

Comments

  • zibadianzibadian Member Posts: 6,349
    : Hello all,
    :
    : I am using this code to drag and drop from a listbox to a richedit.
    : It works when the listbox is on the same form as the richedit but not
    : when the listbox is on a different form:
    : [code]
    : procedure TfrmMain.RE1DragDrop(Sender, Source: TObject; X, Y: Integer);
    : begin
    : // fake mouse click at current cursor position
    : mouse_event( MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 );
    : mouse_event( MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 );
    : // allow control to handle the mouse messages and put the caret at that
    : // position.
    : Application.ProcessMessages;
    : // transfer the text
    : With Source as TListbox Do
    : If ItemIndex >= 0 Then
    : RE1.seltext := '['+Items[itemindex]+']';
    : end;
    :
    : procedure TfrmMain.RE1DragOver(Sender, Source: TObject; X, Y: Integer;
    : State: TDragState; var Accept: Boolean);
    : begin
    : Accept:= Source is TListbox;
    : end;
    : [/code]
    :
    : How can I get it to work?
    :
    : Thanks in advance,
    : James
    :
    Why do you use a fake mouse click to select the item in the listbox? Why not use TListBox.ItemAtPos() to set the ItemIndex without resorting to messages.
Sign In or Register to comment.