How to make the ListBox scroll by using programmatically !

Hi everyone,
As in the subject what I'd like you to help me. Perhaps, It implements so similarly as a words list of a dictionary.

Assuming that, I have a lstName List Box what contains all aphabetical names( ex: It looks like a dictionary ). Now, if the user inputs a name in the txtName TextBox, the lstName will scroll to corresponding position what is located in the lstName(...as the same as in TextBox has a ScrollToCaret to scroll TextBox to the wanted position......).

Let say one example as: I have a lstBox what contains integer number from 0 to 100. It can display from 0 -> 20. Now, if the user inputs 10, so the lstBox will display integer numbers from 10 -> 30. Sequentially, if the user inputs 50 in the text box then the lstBox will show integer numbers from 50 -> 70 by scrolling.

Actually, I want to imitate a dictionary in order to make user easy to search...

I am looking forward to hearing any comments and ideas
Thanks for your help.
[1018 byte] By [vnInformatics] at [2007-11-18 19:15:55]
# 1 Re: How to make the ListBox scroll by using programmatically !
You can do this with API's, but the easiest way is:

Dim iSelectedIndex As Integer = 10

'
'Scroll to very end.
'
ListBox1.SelectedIndex = ListBox1.Items.Count - 1
'
'Now scroll upwards, making it the topmost item.
'
ListBox1.SelectedIndex = iSelectedIndex
Craig Gemmill at 2007-11-10 3:21:26 >
# 2 Re: How to make the ListBox scroll by using programmatically !
Originally posted by Craig Gemmill
You can do this with API's, but the easiest way is:

Dim iSelectedIndex As Integer = 10

'
'Scroll to very end.
'
ListBox1.SelectedIndex = ListBox1.Items.Count - 1
'
'Now scroll upwards, making it the topmost item.
'
ListBox1.SelectedIndex = iSelectedIndex


Thanks in advance, this is smart. Before i always use "ListBox1.SelectedIndex = iSelectedIndex" but havenot tried: "ListBox1.SelectedIndex = ListBox1.Items.Count - 1"...

See you in next thread.
vnInformatics at 2007-11-10 3:22:28 >
# 3 Re: How to make the ListBox scroll by using programmatically !
Why don't you just use Listbox.FindString() and or Listbox.FindStringExact()?
DSJ at 2007-11-10 3:23:26 >
# 4 Re: How to make the ListBox scroll by using programmatically !
Originally posted by DSJ
Why don't you just use Listbox.FindString() and or Listbox.FindStringExact()?

Actually, Two methods: ListBox.FindString() and ListBox.FindStringExact() they will help us find the index of the string parameter what is located in the ListBox.

In here, there are semething different.

as Craig Gemmill guided, It will make the selectedItem is located at the top of appearing screen.

I also want to add something for ListBox.FindString as well as ListBox.FindStringExact().

As we all know that both of two methods will return the index what is firsty appeared matching the string parameter.

Let say one example:
- Now, I have a list what is populated in the ListBox as:
ex01
ex02
ex03
ex031
ex034
ex005

- By using ListBox.FindString or ListBox.FindStringExact(). If I pass "ex031" as a parameter, then the program runs well. But If I pass "ex32" the program will runs ? The position what we want is at: ex034.

For this reason, using both of them will make program more difficult in order to find the closest position.

Looking forward to hearing any comments as well as ideas.
Thanks in advance.
vnInformatics at 2007-11-10 3:24:25 >