472,780 Members | 1,690 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 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 16400
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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.