listview vs listbox?

G

Guest

In ListBox, I can use SelectedIndex to set for current selected item.
for(int x = 0; x <25; x++)
listBox1.Items.Add(x.ToString());

listBox1.SelectedIndex = 10;

How to do the same for ListView?
 
G

Guest

I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


ttan said:
In ListBox, I can use SelectedIndex to set for current selected item.
for(int x = 0; x <25; x++)
listBox1.Items.Add(x.ToString());

listBox1.SelectedIndex = 10;

How to do the same for ListView?

You use ListViewItemItem.Selected , so the code should be:

listview1.Items[ 10].Selected = true;
 
G

Guest

When I use the code you provided, but how come the scroll bar of listview is
not at the position of the selected item. Inlist box when I do selectedIndex
the scroll bar is at the selected position.

Did I missing something?

Ignacio Machin ( .NET/ C# MVP ) said:
Hi,


ttan said:
In ListBox, I can use SelectedIndex to set for current selected item.
for(int x = 0; x <25; x++)
listBox1.Items.Add(x.ToString());

listBox1.SelectedIndex = 10;

How to do the same for ListView?

You use ListViewItemItem.Selected , so the code should be:

listview1.Items[ 10].Selected = true;
 

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

Similar Threads


Top