473,322 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Listbox scroll

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?

--
Semper Fidelis

Adam Klobukowski
at***@gabo.pl
Nov 16 '05 #1
6 11514
Adam Klobukowski <at***@gabo.pl> wrote in
news:cn**********@nemesis.news.tpi.pl:
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.

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 16 '05 #2
Chris R. Timmons napisa³(a):
Adam Klobukowski <at***@gabo.pl> wrote in
news:cn**********@nemesis.news.tpi.pl:

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 :(

--
Semper Fidelis

Adam Klobukowski
at***@gabo.pl
Nov 16 '05 #3
Adam Klobukowski napisa³(a):
Chris R. Timmons napisa³(a):
Adam Klobukowski <at***@gabo.pl> wrote in
news:cn**********@nemesis.news.tpi.pl:
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.

--
Semper Fidelis

Adam Klobukowski
at***@gabo.pl
Nov 16 '05 #4
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" <at***@gabo.pl> wrote in message
news:cn**********@atlantis.news.tpi.pl...
Chris R. Timmons napisa³(a):
Adam Klobukowski <at***@gabo.pl> wrote in
news:cn**********@nemesis.news.tpi.pl:

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 :(

--
Semper Fidelis

Adam Klobukowski
at***@gabo.pl

Nov 16 '05 #5
Adam Klobukowski <at***@gabo.pl> wrote in
news:cn**********@atlantis.news.tpi.pl:
Adam Klobukowski napisa³(a):
Chris R. Timmons napisa³(a):
Adam Klobukowski <at***@gabo.pl> wrote in
news:cn**********@nemesis.news.tpi.pl:

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...).

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 16 '05 #6
Chris R. Timmons napisa³(a):
Adam Klobukowski <at***@gabo.pl> wrote in
news:cn**********@atlantis.news.tpi.pl:

Adam Klobukowski napisa³(a):
Chris R. Timmons napisa³(a):
Adam Klobukowski <at***@gabo.pl> wrote in
news:cn**********@nemesis.news.tpi.pl:
>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.

--
Semper Fidelis

Adam Klobukowski
at***@gabo.pl
Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Filips Benoit | last post by:
Dear All, I have code that selects - find and select - 1 item in a large listbox. This works Ok but most of the time the selected item isn't visible without scrolling down manualy. Is this...
4
by: deko | last post by:
I have an Access 2003 mdb with a Main Form that has a ListBox with a long list of items. The problem is the scroll bar on the ListBox does not scroll all the way to the end unless you first scroll...
1
by: Keltus | last post by:
Hello, I have a Form with a ListBox in it. I'd like to be able to scroll the ListBox even when it's not in focus. ie. when i scroll the mousewheel when my focus is on the form, I'd like the...
1
by: Daniel | last post by:
hi, I had an asp:listbox, and everytime i click item inside, the bar automatically go to the top, is there any way to keep the scroll position? I turn on the smartNavigation, it still doesn't...
2
by: John | last post by:
Hi, I'm currently working on a simple project (for study on C#) with an input (maskedtextbox) and a listbox. The input numbers are send in the listbox. When the listbox is filled with numbers...
3
by: superjacent | last post by:
Hope someone can help. I have a listbox displaying time periods in blocks of 15 mins for a 24 hour period, all up 96 rows. The listbox can only visibly show 20 rows a time. The default...
0
by: R.Nijkamp | last post by:
Hello, i was wondering if its an limitation of IE when a asp.net listbox is set disabled, then a user wont be able to scroll inside the listbox. While the user can scroll inside the listbox when...
7
by: Lit | last post by:
Hi, How can I capture the vertical scroll bar position for a Listbox. I have a Listbox of 100 items + when I click on it I post back remove the item selected. After returning to the client...
5
by: WRH | last post by:
Hello I want to have a multicolumn listbox. I never used one before so I looked at a Help example. I set the multicolumn property and the column width and tested with this example... ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.