Listbox scroll

  • Thread starter Thread starter Adam Klobukowski
  • Start date Start date
A

Adam Klobukowski

Hello.

/windows forms/
I'm marking listbox items as selected, and I'd like to scroll listbox to
a selected entry if it is off-screen. How can I do it?
 
Hello.

/windows forms/
I'm marking listbox items as selected, and I'd like to scroll
listbox to a selected entry if it is off-screen. How can I do
it?

Adam,

Setting ListBox.SelectedIndex should automatically scroll the listbox
to the selected item.
 
Chris R. Timmons napisa³(a):
Adam,

Setting ListBox.SelectedIndex should automatically scroll the listbox
to the selected item.

Ok, but ListBox.SelectedIndex is read only. Should I use property or
method of it? If yes, which one?

I tried something like this:
s_lv.Items[ret].Selected = true;
rozlacz.Enabled = true;
s_lv.SelectedItems[ret].Selected =true;

But it doesn't work :(
 
Adam Klobukowski napisa³(a):
Chris R. Timmons napisa³(a):
Adam,

Setting ListBox.SelectedIndex should automatically scroll the listbox
to the selected item.


Ok, but ListBox.SelectedIndex is read only. Should I use property or
method of it? If yes, which one?

I tried something like this:
s_lv.Items[ret].Selected = true;
rozlacz.Enabled = true;
s_lv.SelectedItems[ret].Selected =true;

But it doesn't work :(

Damn I made mess ;)

It should be:

s_lv.Items[ret].Selected = true;
s_lv.SelectedItems[0].Selected =true;

And it is not a lisbox but listview and it has multiselect=false property.
 
ListBox.SelectedIndex is read/write, so just set it to the zero based index
you want to be selected in the listbox.

s_lv.SelectedIndex = 3;

--Liam.

Adam Klobukowski said:
Chris R. Timmons napisa³(a):
Adam,

Setting ListBox.SelectedIndex should automatically scroll the listbox
to the selected item.

Ok, but ListBox.SelectedIndex is read only. Should I use property or
method of it? If yes, which one?

I tried something like this:
s_lv.Items[ret].Selected = true;
rozlacz.Enabled = true;
s_lv.SelectedItems[ret].Selected =true;

But it doesn't work :(

--
Semper Fidelis

Adam Klobukowski
(e-mail address removed)
 
Adam Klobukowski napisa³(a):
Chris R. Timmons napisa³(a):
Hello.

/windows forms/
I'm marking listbox items as selected, and I'd like to scroll
listbox to a selected entry if it is off-screen. How can I do
it?



Adam,

Setting ListBox.SelectedIndex should automatically scroll the
listbox to the selected item.


Ok, but ListBox.SelectedIndex is read only. Should I use
property or method of it? If yes, which one?

I tried something like this:
s_lv.Items[ret].Selected = true;
rozlacz.Enabled = true;
s_lv.SelectedItems[ret].Selected =true;

But it doesn't work :(

Damn I made mess ;)

It should be:

s_lv.Items[ret].Selected = true;
s_lv.SelectedItems[0].Selected =true;

And it is not a lisbox but listview and it has multiselect=false
property.

Adam,

Try this:

this.listView1.Select();
this.listView1.Items[ret].Selected = true;
this.listView1.EnsureVisible(ret);

The ListView has to be selected before it will honor a request to
programmatically select an item (I don't know why...).
 
Chris R. Timmons napisa³(a):
Adam Klobukowski napisa³(a):
Chris R. Timmons napisa³(a):




Hello.

/windows forms/
I'm marking listbox items as selected, and I'd like to scroll
listbox to a selected entry if it is off-screen. How can I do
it?



Adam,

Setting ListBox.SelectedIndex should automatically scroll the
listbox to the selected item.


Ok, but ListBox.SelectedIndex is read only. Should I use
property or method of it? If yes, which one?

I tried something like this:
s_lv.Items[ret].Selected = true;
rozlacz.Enabled = true;
s_lv.SelectedItems[ret].Selected =true;

But it doesn't work :(

Damn I made mess ;)

It should be:

s_lv.Items[ret].Selected = true;
s_lv.SelectedItems[0].Selected =true;

And it is not a lisbox but listview and it has multiselect=false
property.


Adam,

Try this:

this.listView1.Select();
this.listView1.Items[ret].Selected = true;
this.listView1.EnsureVisible(ret);

The ListView has to be selected before it will honor a request to
programmatically select an item (I don't know why...).

It works, thanks.
 
Back
Top