Find text and get line number in listbox

Topics: User Forum
Jul 14, 2012 at 10:49 PM
Edited Jul 14, 2012 at 10:51 PM

hi,

i'd like to know how can i find some text in the scintilla control and how to add the line number of found text to a listbox, then when i click the result into the listbox i'd like to jump at the respective line in the scintilla textbox. i looked all the discussions but i've not found a solution.

I like to do something like this:

foreach (string value in scintilla)
	{
	    listbox.item.add(scintilla line number)
	}
        
        private void lbox_DoubleClick(object sender, EventArgs e)
 {
goto_scintilla_line(lbox.SelectedItem.ToString());
}

Thanks in advanced

Coordinator
Jul 17, 2012 at 4:48 PM

To get all lines for a search

foreach(var range = Scintilla.FindReplace.FindAll(searchString))
	listbox.Items.Add(range.StartingLine.Number);

To get the current line # where the cursor is

currentLineNumber = Scintilla.Caret.LineNumber;

To go to at line 

Scintilla.GoTo.Line(lineNumber);
Jul 17, 2012 at 9:48 PM

hi, thanks for your reply btw i can't get the row number using your example code

eg.

foreach (var item in sc.FindReplace.FindAll(tf.Text))
            {
                lb.Items.Add(item.ToString());
            }

this loop push something like this "{Start=1319, End=1324, Length=5}" into the listbox i think it is a sort of coordinates

 also this one doesn't works

lb.Items.Add(range.StartingLine.Number);

"System.Collections.Generic.List<ScintillaNET.Range>' does not contain a definition for 'StartingLine' and no extension method 'StartingLine' accepting a first argument of type"

thanks

Coordinator
Aug 22, 2012 at 4:24 AM

StartingLine is a property of the ScintillaNET.Range object, not the List<ScintillaNET.Range> object -- hence the error.

Also the reason you see "{Start=1319, End=1324, Length=5}" in your ListBox is because the ListBox control calls ToString on any object in its collection to create the display value. That text is the representation of the Range object, not the StartingLine.Number property which is what you want.

Chris's example is exactly what you need.

 

Jacob