listview vs listbox?

  • Thread starter Thread starter Guest
  • Start date Start date
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?
 
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;
 
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;
 
Back
Top