Forum > RichMemo

RichMemo Scrolls when using SelText

(1/1)

bungayst:
How do I stop this from happening? It's affecting the usability of the application.
When dragging text from a TreeView into a RichMemo the text scrolls/jumps and the user looses their place.

procedure TForm1.RichMemo1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
  iNode  : String;
begin
  iNode := TTreeview(Source).Selected.Text; //Treeview is the Source.

// SelStart causes RichMemo to jump/scroll. Can this be stopped?
    RichMemo1.SelStart:=RichMemo1.CharAtPos(0,Y);
    RichMemo1.SelText:=iNode;
end;       

skalogryz:
you can try to do something like that:

--- Code: Text  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.RichMemo1DragDrop(Sender, Source: TObject; X, Y: Integer);var  iNode  : String;  v : integer;begin  iNode := TTreeview(Source).Selected.Text; //Treeview is the Source. // SelStart causes RichMemo to jump/scroll. Can this be stopped?    v := RichMemo1.VertScrollBar.Position;    RichMemo1.SelStart:=RichMemo1.CharAtPos(0,Y);    RichMemo1.SelText:=iNode;    RichMemo1.VertScrollBar.Position := v;end;     

bungayst:
I'm playing with this solution now. It doesn't throw any errors but it's not doing anything. Very strange.

The procedure now looks like this;

procedure TForm1.RichMemo1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
  iNode  : String;
  v : Integer;

begin
  iNode := TTreeview(Source).Selected.Text; //Treeview is the Source.

  // Preserve the position of the Vertical Scrollbar
  v := RichMemo1.VertScrollBar.Position;
  // Set the starting position for the text to be inserted into the RichMemo
  RichMemo1.SelStart := RichMemo1.CharAtPos(0,Y);
  // Insert the text
  RichMemo1.SelText := iNode;
  // Reset the position of the Vertical Scrollbar
  RichMemo1.VertScrollBar.Position := v;
  // Put the values of v and RichMemo1.VertScrollBar.Position into two text boxes, lets see if they differ.
  Edit2.Text := IntToStr(v);
  Edit3.Text := IntToStr(RichMemo1.VertScrollBar.Position);
end; 

  And the result is that the values DO differ. The value of v, it seems, is not being stored in (accepted by?) RichMemo1.VertScrollBar.Position, and as a result the RichMemo keeps doing its thing. Most frustrating.

Navigation

[0] Message Index

Go to full version