473,386 Members | 2,114 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,386 software developers and data experts.

How to scroll at the last item in the listbox through an event

GG
I know I can scroll to the last item in the listbox by calling
SetSelected all the time
What I need is when I add items through the Items.Add or Items.AddRange
to be called automatically and go the the bottom.
Anybody knows how to be implemented?

Thanks

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
5 16451
Derive from ListBox. Override the add and addrange to work the way you want.

"GG" wrote:
I know I can scroll to the last item in the listbox by calling
SetSelected all the time
What I need is when I add items through the Items.Add or Items.AddRange
to be called automatically and go the the bottom.
Anybody knows how to be implemented?

Thanks

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #2


Well, there isn't an ItemsAdded event on the listbox, but you could build
one if you wanted.

This is just a thought, but does adding an item trigger a resize? If so,
then you could add the logic to select the last item at the resize event.

-James

"GG" wrote:
I know I can scroll to the last item in the listbox by calling
SetSelected all the time
What I need is when I add items through the Items.Add or Items.AddRange
to be called automatically and go the the bottom.
Anybody knows how to be implemented?

Thanks

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #3
GG
Thanks
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #4
GG
Added the code to SizeChanged and works like a charm
if (lstMsgs.Items.Count==0)
return;
//This selects and highlights the last line
this.lstMsgs.SetSelected(lstMsgs.Items.Count - 1, true);
//This unhighlights the last line
this.lstMsgs.SetSelected(lstMsgs.Items.Count - 1, false);

This is the code in case somebody needs it
Thanks
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5
GG
Will take it back. It does not work.

I ended up having a separate proc like this
private void lstMsgsItemsAddScrollBottom(object item)
{
this.lstMsgs.Items.Add(item);
//This selects and highlights the last line
this.lstMsgs.SetSelected(lstMsgs.Items.Count - 1, true);
//This unhighlights the last line
this.lstMsgs.SetSelected(lstMsgs.Items.Count - 1, false);
}
and call this one instead of items.add

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #6

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...
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...
12
by: Jim H | last post by:
I have a ListBox hold a list of my custom controls (it's UserControl based control with a couple radio buttons and a checkbox). Everything works and displays the way I expected it to. I can move...
6
by: Adam Klobukowski | last post by:
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
1
by: jez123456 | last post by:
Hi, I have a windows form with a listbox control. My code all works correctly when deleting an item from the listbox except the last item. I get the following message when trying to delete the...
5
by: John Veldthuis | last post by:
My code works perfectly 100% when adding items to my ArrayList and updating the listbox. Works perfectly when deleting an item in the ArrayList when it is not the last entry but if it is the last...
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...
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.