473,382 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Searching a textbox

I am using VB.NET 2008.
I would like to search a textbox (find next and find previous), and when it
finds the text, move my cursor in the textbox to where the found text is.
How can I do that ?
Thank you
Jun 27 '08 #1
8 4864
On Jun 9, 5:41 pm, "fniles" <fni...@pfmail.comwrote:
I am using VB.NET 2008.
I would like to search a textbox (find next and find previous), and when it
finds the text, move my cursor in the textbox to where the found text is.
How can I do that ?
Thank you
Hi fniles,
Though I've struggled a bit excessive, here is some code that
highlights the text piece in "textbox1" what you entered in "textbox2"
on a button click:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
TextBox1.Focus()
TextBox1.SelectionStart = TextBox1.Text.IndexOf(TextBox2.Text)
TextBox1.SelectionLength = TextBox2.Text.Length
End Sub

' Note: That only finds the first text piece in the whole textbox1

Hope this helps,

Onur Güzel
Jun 27 '08 #2
Thank you.
If the found text is on page 2, how do I move my scroll bar so that it will
be on the 2nd page ?
Right now, the found text is highlighted, but I am still on the 1st page,
not until I page down to the 2nd page I will see the highlighted text.

Thanks

"kimiraikkonen" <ki*************@gmail.comwrote in message
news:d9**********************************@59g2000h sb.googlegroups.com...
On Jun 9, 5:41 pm, "fniles" <fni...@pfmail.comwrote:
I am using VB.NET 2008.
I would like to search a textbox (find next and find previous), and when
it
finds the text, move my cursor in the textbox to where the found text is.
How can I do that ?
Thank you
Hi fniles,
Though I've struggled a bit excessive, here is some code that
highlights the text piece in "textbox1" what you entered in "textbox2"
on a button click:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
TextBox1.Focus()
TextBox1.SelectionStart = TextBox1.Text.IndexOf(TextBox2.Text)
TextBox1.SelectionLength = TextBox2.Text.Length
End Sub

' Note: That only finds the first text piece in the whole textbox1

Hope this helps,

Onur Güzel
Jun 27 '08 #3
On Jun 9, 7:47*pm, "fniles" <fni...@pfmail.comwrote:
Thank you.
If the found text is on page 2, how do I move my scroll bar so that it will
be on the 2nd page ?
Right now, the found text is highlighted, but I am still on the 1st page,
not until I page down to the 2nd page I will see the highlighted text.

Thanks

"kimiraikkonen" <kimiraikkone...@gmail.comwrote in message

news:d9**********************************@59g2000h sb.googlegroups.com...
On Jun 9, 5:41 pm, "fniles" <fni...@pfmail.comwrote:
I am using VB.NET 2008.
I would like to search a textbox (find next and find previous), and when
it
finds the text, move my cursor in the textbox to where the found text is..
How can I do that ?
Thank you

Hi fniles,
Though I've struggled a bit excessive, here is some code that
highlights the text piece in "textbox1" what you entered in "textbox2"
on a button click:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
TextBox1.Focus()
TextBox1.SelectionStart = TextBox1.Text.IndexOf(TextBox2.Text)
TextBox1.SelectionLength = TextBox2.Text.Length
End Sub

' Note: That only finds the first text piece in the whole textbox1

Hope this helps,

Onur Güzel
You want something like MS Word's paged layout. The sample above does
the job in Textbox control which does not support a kind of layout
like seperate pages, as you requested as "textbox" in your first post.
So the implementation may depend on how to use "pages" and how you
mean pages in your project. What exactly do you mean by calling
"pages"? Seperate textboxes , RichTextBox or other control?

Thanks,

Onur Güzel
Jun 27 '08 #4
Thank you for your reply.
I am using textbox with "MultiLine" set to yes, and I set "scroll bar" to
"both".
For example, say I have 2 pages of data (meaning, I can only go to the 2nd
page of data when I hit the vertical scroll on the textbox), and my search
word is found on the 2nd page.
How can I automatically scroll to the 2nd page of the multiline text box ?

Thank you.

"kimiraikkonen" <ki*************@gmail.comwrote in message
news:f0**********************************@k13g2000 hse.googlegroups.com...
On Jun 9, 7:47 pm, "fniles" <fni...@pfmail.comwrote:
Thank you.
If the found text is on page 2, how do I move my scroll bar so that it
will
be on the 2nd page ?
Right now, the found text is highlighted, but I am still on the 1st page,
not until I page down to the 2nd page I will see the highlighted text.

Thanks

"kimiraikkonen" <kimiraikkone...@gmail.comwrote in message

news:d9**********************************@59g2000h sb.googlegroups.com...
On Jun 9, 5:41 pm, "fniles" <fni...@pfmail.comwrote:
I am using VB.NET 2008.
I would like to search a textbox (find next and find previous), and when
it
finds the text, move my cursor in the textbox to where the found text
is.
How can I do that ?
Thank you

Hi fniles,
Though I've struggled a bit excessive, here is some code that
highlights the text piece in "textbox1" what you entered in "textbox2"
on a button click:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
TextBox1.Focus()
TextBox1.SelectionStart = TextBox1.Text.IndexOf(TextBox2.Text)
TextBox1.SelectionLength = TextBox2.Text.Length
End Sub

' Note: That only finds the first text piece in the whole textbox1

Hope this helps,

Onur Güzel
You want something like MS Word's paged layout. The sample above does
the job in Textbox control which does not support a kind of layout
like seperate pages, as you requested as "textbox" in your first post.
So the implementation may depend on how to use "pages" and how you
mean pages in your project. What exactly do you mean by calling
"pages"? Seperate textboxes , RichTextBox or other control?

Thanks,

Onur Güzel
Jun 27 '08 #5

"fniles" <fn****@pfmail.comkirjoitti viestissä
news:eO**************@TK2MSFTNGP06.phx.gbl...
Thank you for your reply.
I am using textbox with "MultiLine" set to yes, and I set "scroll bar" to
"both".
For example, say I have 2 pages of data (meaning, I can only go to the 2nd
page of data when I hit the vertical scroll on the textbox), and my search
word is found on the 2nd page.
How can I automatically scroll to the 2nd page of the multiline text box ?
TextBox1.ScrollToCaret() will do the trick.

-Teemu

Jun 27 '08 #6
On Jun 9, 9:09 pm, "fniles" <fni...@pfmail.comwrote:
Thank you for your reply.
I am using textbox with "MultiLine" set to yes, and I set "scroll bar" to
"both".
For example, say I have 2 pages of data (meaning, I can only go to the 2nd
page of data when I hit the vertical scroll on the textbox), and my search
word is found on the 2nd page.
How can I automatically scroll to the 2nd page of the multiline text box ?

Thank you.

"kimiraikkonen" <kimiraikkone...@gmail.comwrote in message

news:f0**********************************@k13g2000 hse.googlegroups.com...
On Jun 9, 7:47 pm, "fniles" <fni...@pfmail.comwrote:
Thank you.
If the found text is on page 2, how do I move my scroll bar so that it
will
be on the 2nd page ?
Right now, the found text is highlighted, but I am still on the 1st page,
not until I page down to the 2nd page I will see the highlighted text.
Thanks
"kimiraikkonen" <kimiraikkone...@gmail.comwrote in message
news:d9**********************************@59g2000h sb.googlegroups.com...
On Jun 9, 5:41 pm, "fniles" <fni...@pfmail.comwrote:
I am using VB.NET 2008.
I would like to search a textbox (find next and find previous), and when
it
finds the text, move my cursor in the textbox to where the found text
is.
How can I do that ?
Thank you
Hi fniles,
Though I've struggled a bit excessive, here is some code that
highlights the text piece in "textbox1" what you entered in "textbox2"
on a button click:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
TextBox1.Focus()
TextBox1.SelectionStart = TextBox1.Text.IndexOf(TextBox2.Text)
TextBox1.SelectionLength = TextBox2.Text.Length
End Sub
' Note: That only finds the first text piece in the whole textbox1
Hope this helps,
Onur Güzel

You want something like MS Word's paged layout. The sample above does
the job in Textbox control which does not support a kind of layout
like seperate pages, as you requested as "textbox" in your first post.
So the implementation may depend on how to use "pages" and how you
mean pages in your project. What exactly do you mean by calling
"pages"? Seperate textboxes , RichTextBox or other control?

Thanks,

Onur Güzel
Now i hope i understood, you're talking about one and the same textbox
control which is structured by your own as pages, so you want your
unique textbox to be scrolled when and where the text is found?

So, i've found ScrollToCaret method which should do what you want, so
the extended code will look like this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
TextBox1.Focus()
TextBox1.SelectionStart = TextBox1.Text.IndexOf(TextBox2.Text)
TextBox1.SelectionLength = TextBox2.Text.Length
' Go to selectedtext piece and scrool
TextBox1.ScrollToCaret()
End Sub

Hope this helps, let us know...

Thanks,

Onur Güzel
Jun 27 '08 #7
Thank you very much for your help.
That's what I was looking for.

Thanks again

"kimiraikkonen" <ki*************@gmail.comwrote in message
news:f0**********************************@k37g2000 hsf.googlegroups.com...
On Jun 9, 9:09 pm, "fniles" <fni...@pfmail.comwrote:
Thank you for your reply.
I am using textbox with "MultiLine" set to yes, and I set "scroll bar" to
"both".
For example, say I have 2 pages of data (meaning, I can only go to the 2nd
page of data when I hit the vertical scroll on the textbox), and my search
word is found on the 2nd page.
How can I automatically scroll to the 2nd page of the multiline text box ?

Thank you.

"kimiraikkonen" <kimiraikkone...@gmail.comwrote in message

news:f0**********************************@k13g2000 hse.googlegroups.com...
On Jun 9, 7:47 pm, "fniles" <fni...@pfmail.comwrote:
Thank you.
If the found text is on page 2, how do I move my scroll bar so that it
will
be on the 2nd page ?
Right now, the found text is highlighted, but I am still on the 1st
page,
not until I page down to the 2nd page I will see the highlighted text.
Thanks
"kimiraikkonen" <kimiraikkone...@gmail.comwrote in message
news:d9**********************************@59g2000h sb.googlegroups.com...
On Jun 9, 5:41 pm, "fniles" <fni...@pfmail.comwrote:
I am using VB.NET 2008.
I would like to search a textbox (find next and find previous), and
when
it
finds the text, move my cursor in the textbox to where the found text
is.
How can I do that ?
Thank you
Hi fniles,
Though I've struggled a bit excessive, here is some code that
highlights the text piece in "textbox1" what you entered in "textbox2"
on a button click:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
TextBox1.Focus()
TextBox1.SelectionStart = TextBox1.Text.IndexOf(TextBox2.Text)
TextBox1.SelectionLength = TextBox2.Text.Length
End Sub
' Note: That only finds the first text piece in the whole textbox1
Hope this helps,
Onur Güzel

You want something like MS Word's paged layout. The sample above does
the job in Textbox control which does not support a kind of layout
like seperate pages, as you requested as "textbox" in your first post.
So the implementation may depend on how to use "pages" and how you
mean pages in your project. What exactly do you mean by calling
"pages"? Seperate textboxes , RichTextBox or other control?

Thanks,

Onur Güzel
Now i hope i understood, you're talking about one and the same textbox
control which is structured by your own as pages, so you want your
unique textbox to be scrolled when and where the text is found?

So, i've found ScrollToCaret method which should do what you want, so
the extended code will look like this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
TextBox1.Focus()
TextBox1.SelectionStart = TextBox1.Text.IndexOf(TextBox2.Text)
TextBox1.SelectionLength = TextBox2.Text.Length
' Go to selectedtext piece and scrool
TextBox1.ScrollToCaret()
End Sub

Hope this helps, let us know...

Thanks,

Onur Güzel
Jun 27 '08 #8
Thank you very much for your help.

"Teemu" <ts*****@hotmail.comwrote in message
news:rH******************@reader1.news.saunalahti. fi...
>
"fniles" <fn****@pfmail.comkirjoitti viestissä
news:eO**************@TK2MSFTNGP06.phx.gbl...
>Thank you for your reply.
I am using textbox with "MultiLine" set to yes, and I set "scroll bar" to
"both".
For example, say I have 2 pages of data (meaning, I can only go to the
2nd page of data when I hit the vertical scroll on the textbox), and my
search word is found on the 2nd page.
How can I automatically scroll to the 2nd page of the multiline text box
?

TextBox1.ScrollToCaret() will do the trick.

-Teemu

Jun 27 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: donald | last post by:
Hi all, I have a website running asp (about to move to asp.net soon though) which has a list of DVD's I have the various pages I want, last 10, listing, full listing ect, but the one page i can't...
3
by: MoonWa | last post by:
Short of going char by char, how do I search for a pattern in the text for a textbox Thanks MoonWa
5
by: Andy | last post by:
I am having trouble using the ComboBox in my app. I am attempting to use the text from the ComboBox, to search the list box portion. However: In my "TextChanged" event: I cannot get the value...
4
by: libsfan01 | last post by:
Im not entirely sure this involves JS but bear with me... I'm looking to implement a system on a site where the user starts to type in the search box (textbox) what they are looking for and this...
1
by: sivagururaja | last post by:
Hi All, Im using ASP.NET with C#. (.NET 2005) In my page i want to allow the user to search the text from the SQL table. This is my table ID Name City State 1 Parry ...
6
by: Wout86 | last post by:
This is my first posting. Can you help me with this, please. I know how to search for a word in a TextBox control and highlight it when found. Then step through the textbox for any further words....
2
by: =?Utf-8?B?VGVycnk=?= | last post by:
I am implementing an 'incremental search', where as the user types into a textbox, a datagridview's current position is updated to match the first record that contains what the user has typed so...
2
by: wietmie | last post by:
Hai, i just wanna ask, is it possible to do a searching result like google using VB6.0, but google are too complicated, what i mean just, user put the searching word in the textbox, then it will...
4
by: aaronkmar | last post by:
Hello Bytes, I hope this post finds you well on this wonderful Friday! I've been kicking this code around for over a week now and cannot seem to find the correct syntax to handle all of the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.