Results 1 to 2 of 2

Thread: [1.0/1.1] Listbox focus always on the last line/item added? [C# 2002]

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Posts
    308

    Question [1.0/1.1] Listbox focus always on the last line/item added? [C# 2002]

    This is going to be fun to explain...
    I am using the LISTBOX (lbOutput) as a way to output information to the user (via the lbOutput.items.add(sInfo);) - when the listbox itself gets full the scrollbars appear except that the focus remains at the top of the listbox.

    As lines keep getting added the user has to scroll DOWN to see the information. I need the opposite, I need to ensure the Listbox will always show the LAST ITEM ADDED at all times, if the user wants to see what happened before he can easily scroll up using the scroll bars. Kind of like how the command prompt works.

    I went through the ListBox properties and was unable to find anything to that effect - any ideas?
    Any help would be greatly appreciated...
    Thanks,

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [1.0/1.1] Listbox focus always on the last line/item added? [C# 2002]

    Are you sure that a ListBox is the appropriate control for that. It sounds like a TextBox may be a better option, perhaps with its ReadOnly property set to True. Then you just call AppendText and the new string will be added to the end and the caret set at the end of the text.

    If you do stick with a ListBox I believe this should have the desired effect:
    C# Code:
    1. this.ListBox1.TopIndex = this.ListBox1.Items.Count - 1;
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width