Thread: Auto Scroll a ListBox

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    6

    Auto Scroll a ListBox

    I have a program with a listbox that has alot of stuff added to it. My problem is that I want the window to automatically scroll so that the newest item is visible at the bottom, currently the user has to scroll down to see any new items added.
    I'm using Visual C++ 6.0 and the default listboxes, I've tried changing the various choices under properties for it but none have worked so far. Hopefully this is something simple I'm missing, heh, thanks in advance for any replies.

  2. #2
    Send the LB_SELECTSTRING message to the control.

    LB_SELECTSTRING
    wParam = (WPARAM) indexStart; // item before start of search
    lParam = (LPARAM)(LPCTSTR)lpszFind; // address of search string

    indexStart
    Value of wParam. Specifies the zero-based index of the item before the first item to be searched. When the search reaches the bottom of the list box, it continues from the top of the list box back to the item specified by the indexStart parameter. If indexStart is –1, the entire list box is searched from the beginning.
    Windows 95 and Windows 98: The wParam parameter is limited to 16-bit values. This means list boxes cannot contain more than 32,767 items. Although the number of items is restricted, the total size in bytes of the items in a list box is limited only by available memory.

    lpszFind
    Value of lParam. Pointer to the null-terminated string that contains the prefix to search for. The search is case independent, so this string can contain any combination of uppercase and lowercase letters.
    Return Values
    If the search is successful, the return value is the index of the selected item. If the search is unsuccessful, the return value is LB_ERR and the current selection is not changed.

    You may also want to use LB_FINDSTRING to find the last inserted item to use as the index if there can be multiple instances of the same string.
    Last edited by Mithoric; 12-20-2003 at 12:45 AM.

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    6
    Thank you for the reply, I used that function and now it's almost working perfectly heh. My problem now is that, I'm using the listbox for a chat area, the program is Tic Tac Toe and you can connect to another computer to play it. The listbox now scrolls down if a new message comes in, unless the message is the same as the previous one. That's a pretty minor bug I can live with, but do you know how to fix that?


    Heh, you updated on me while I was posting! I'll give that a try and see if I can get it to work.

  4. #4
    Yeah, I gathered that you might have that problem so I put in the extra info.

  5. #5
    Registered User
    Join Date
    Nov 2003
    Posts
    6
    Woo! I got it working, I had to use GetCount instead of FindString because FindString did the same thing as SelectString pretty much. Thank you for your help, this has been driving me nuts for a long time.

  6. #6
    Hehe, no problem!

  7. #7
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    alos look at ENSUREVISIBLE
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Scroll Bars Are Scrolling Me Crazy
    By Iyouboushi in forum C# Programming
    Replies: 6
    Last Post: 03-03-2006, 01:43 PM
  2. How to cast a ListBox item to an int for a switch statment?
    By Swaine777 in forum C++ Programming
    Replies: 8
    Last Post: 09-26-2004, 08:52 PM
  3. Code: An auto expanding array (or how to use gets() safely).
    By anonytmouse in forum Windows Programming
    Replies: 0
    Last Post: 08-10-2004, 12:13 AM
  4. Windows 98 Auto Scroll Problem
    By StanleyC in forum Windows Programming
    Replies: 2
    Last Post: 04-26-2004, 08:05 AM
  5. Horizontal Scroll Bars with CListBox
    By Malek in forum Windows Programming
    Replies: 1
    Last Post: 04-10-2003, 09:58 PM