Scroll line into view

SyntaxEditor for Windows Forms Forum

Posted 12 years ago by John McLemore
Version: 4.0.0255
Avatar
I am trying to scroll a stored line index into view in the syntax editor I have after a modification.

The user has the ability to view code in the syntax editor, change a property from a property grid, which edits code and gets loaded into the syntax editor.

I reload the modified code into the syntax editor after the code string is modified. Before I reload the code into the editor, I store the line index of the current displayed line. Then I set the Text property of the syntax editor. Once the code is loaded, I set the first visible line index to the index I saved previously, then I call the ScrollLineToVisibleTop() method.

The code in the syntax editor is not scrolled to the line index I set. It keeps jumping to the first line of code in the syntax editor. Is there some way I can perform this? Am I on the right track, or am I simply missing something? Any help would be appreciated. (Sample code follows)

// Save our line index so we can keep the modified code in view
int nStartPos = editor.SelectedView.FirstVisibleDisplayLineIndex;
editor.Text = this.CS_Code; // Load the modified code into the editor
editor.SelectedView.FirstVisibleDisplayLineIndex = nStartPos;
editor.SelectedView.ScrollLineToVisibleTop();

Comments (2)

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi John,

I don't think you need that last line. Simply setting FirstVisibleDisplayLineIndex should do what you want, unless I'm reading your message wrong.


Actipro Software Support

Posted 12 years ago by John McLemore
Avatar
Thank you for your prompt response!

I apologize for wasting your time. I stepped through the code again and found another event which was loading the code into the syntax editor AFTER I set the visible line index and this event was not setting the visible line. I have corrected the problem and everything works fine.

Again, thanks for your help and speedy response. :D
The latest build of this product (v2020.1 build 0400) was released 5 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.