Setting focus to a line in the script

Hi-
I am using the DebugCodeEdit control. If a file is already loaded in the control, I can tell it to focus a line using this code and it scrolls to the line and highlights it:
EditorControl.Position = start;
EditorControl.Focus();
EditorControl.Selection.SetSelection(SelectionType.Stream, start, end);
If I try to put the same code in the Loaded event on the control (to focus a line when the file opens), nothing happens.
I have tried using an ExecutionPosition and calling ExecutionStopped and then focus. This works if the file is already open, but does not work in the Loaded event.
Is there another event that I can use to focus a line immediately after a file is loaded?
Thanks!
Hi,
As I understand you use WPF version of our control.
Using DebugCodeEdit.Loaded event works well for me. Could you please try this code:
edit.Loaded += Edit_Loaded;
private void Edit_Loaded(object sender, RoutedEventArgs e)
{
if (sender == null)
return;
var edit = sender as DebugCodeEdit;
if (edit != null)
{
edit.Position = start;
edit.Focus();
edit.Selection.SetSelection(SelectionType.Stream, start, end);
}
}
Regards,
Andrew
I finally got it to work and I'm adding a small explanation in case anyone else runs into this.
We use the mvvm pattern. The control was defined in the xaml and the load event was connected to a command in the view model. When the load event fired, I was setting up the lexar, the editor's source and calling editor.source.loadfile. After doing a few more tasks, I was doing almost exactly as you wrote to set the position in the script. This last part was not working, but I could successfully set the position anytime after the screen was shown.
The only way I could get the load event to set the position correctly was by breaking mvvm :) . I followed one of the examples and dynamically created the DebugCodeEdit in the code behind on another control's load event, set up parser & source file and then set up the DebugCodeEdit's load event handler. Now the only thing the DebugCodeEdit's load event does is set the position in the script - and it works.