Listview Selected Item

B

Bill-R

I'm trying to convert a vb6 program to vb.net (vb2008 express)

I have text data in a Listview Control
I use a Textbox to enter characters to search the Listview
When a Match is found, I use textbox_textchanged to select listview item

Listview1.Items(z).Selected = True
Listview1.Items(z).EnsureVisible ()
Listview1.Items(z).FullRowSelect = True
Listview1.Items(z).ForeColor = Blue

This works fine .

Then when I hit a Aarrow key in the textbox
I set focus to the listview (Listview1.Focus()

Now if I hit a arrow key to scroll the listview, it jumps to the last place
that was Physically selected. or in case of the first hit it starts at the
top of the listview.

In vb6 the same code would start the listview scroll from the selected item.

What am I missing ????
 
K

kimiraikkonen

I'm trying to convert a vb6 program to vb.net (vb2008 express)

I have text data in a Listview Control
I use a Textbox to enter characters to search the Listview
When a Match is found, I use textbox_textchanged to select listview  item

Listview1.Items(z).Selected = True
Listview1.Items(z).EnsureVisible ()
Listview1.Items(z).FullRowSelect = True
Listview1.Items(z).ForeColor = Blue

This works fine .

Then when I hit a Aarrow key in the textbox
I set focus to the listview (Listview1.Focus()

Now if I hit a arrow key to scroll the listview, it jumps to the last place
that was Physically selected. or in case of the first hit it starts at the
top of the listview.

In vb6 the same code would start the listview scroll from the selected item.

What am I missing ????

If the same code was working with no problem in VB6, i recommend you
to check the listview control's "properties" in properties window.
Compare both platform's listviews to ensure they have the same
properties of VB6's.
 
T

Teemu

Bill-R said:
I'm trying to convert a vb6 program to vb.net (vb2008 express)

I have text data in a Listview Control
I use a Textbox to enter characters to search the Listview
When a Match is found, I use textbox_textchanged to select listview item

Listview1.Items(z).Selected = True
Listview1.Items(z).EnsureVisible ()
Listview1.Items(z).FullRowSelect = True
Listview1.Items(z).ForeColor = Blue

This works fine .

Then when I hit a Aarrow key in the textbox
I set focus to the listview (Listview1.Focus()

Now if I hit a arrow key to scroll the listview, it jumps to the last
place that was Physically selected. or in case of the first hit it starts
at the top of the listview.

In vb6 the same code would start the listview scroll from the selected
item.

What am I missing ????

When setting focus to Listview1, try this code:

ListView1.Items(z).Focused = True

-Teemu
 
T

Teemu

"Teemu" <[email protected]> kirjoitti viestissä

Or actually my answer was a bit wrong.

When selecting the item:

Listview1.Items(z).Selected = True
Listview1.Items(z).Focused= True
Listview1.Items(z).EnsureVisible ()
Listview1.FullRowSelect = True
Listview1.Items(z).ForeColor = Blue

And then

Listview1.Focus()

to activate the Listview1.

-Teemu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top