Re: Max number of items in a listbox?

From: Martin (martinvalley_at_comcast.net)
Date: 06/14/04


Date: Mon, 14 Jun 2004 10:28:42 -0700

I added code as you suggested and it does limit the number of items in
the list.

However, this "broke" another feature that I had working and I can't
figure out how to get around it. Perhaps you might have an idea?

I have some code in the program (just after an item is added) that
causes the list to auto-scroll when an item is added but only when the
slider bar is all the way down. If the user has scrolled up in to the
list somewhere and is reading something, the list won't jump back down
to the bottom when another item is added.

FWIW, this is accomplished with the following statement (constX is set
at design time and is one greater than the number of items that are
visible in the list):

If List1.ListCount - List1.TopIndex = constX Then
   List1.TopIndex = List1.ListCount - 1
End If

What's happening now is, when the .RemoveItem 0 executes, the list
automatically refreshes and scrolls up no matter what part of the list
is being viewed.

Do you know if there is any way to keep this from happening?

On Mon, 14 Jun 2004 17:04:23 +0200, "Björn Holmgren"
<bjohol@hotmail.com> wrote:

>"Martin" <martinvalley@comcast.net> wrote in message
>news:frerc017sjhrlb0mbkotm677n5ln8pjjf4@4ax.com...
>> Thanks.
>>
>> Yes, I agree regarding UI design. In this instance, I'm using a
>> ListBox as sort of an event log. My program communicates with other
>> devices and I provided some trouble-shooting screens with the logging
>> being able to be turned on and off. It just dawned on me that I'm not
>> limiting the number of entries that can accumulate in this listbox
>> and, if the user were to let it run for a day or so, I could get to a
>> point where the program could crash. I need to add some code to remove
>> entries from the top of the list when the listcount exceeds some
>> number (probably 5000 entries).
>
>
>Ahhh, an event log. Ok, something like this then:
>
>'----------
>Sub AddLogEntry(sText As String, iMaxItems As Integer)
> If List1.ListCount >= iMaxItems Then List1.RemoveItem 0
> List1.AddItem sText
> List1.ListIndex = List1.ListCount - 1
>End Sub



Relevant Pages

  • Re: Max number of items in a listbox?
    ... > ListBox as sort of an event log. ... > limiting the number of entries that can accumulate in this listbox ... Ahhh, an event log. ... Sub AddLogEntry ...
    (microsoft.public.vb.general.discussion)
  • Re: Setting Listbox Size VBA
    ... Sub TestListBox() ... Not got a clue about A-Z ing the list box but this seems to do the basic ... varies in the number of entries there are. ... Anyway, if I use the list as is, my listbox contains 22 blank entries. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Max number of items in a listbox?
    ... ListBox as sort of an event log. ... My program communicates with other ... limiting the number of entries that can accumulate in this listbox ...
    (microsoft.public.vb.general.discussion)
  • Re: Listbox selectedindex changed event not firing from within datagrid
    ... the listbox to the command button. ... Private Sub DataGrid1_ItemCreated(ByVal sender As Object, ... >> Although you have added SelectedIndexChanged event handler for ListBox, ...
    (microsoft.public.dotnet.framework.aspnet.datagridcontrol)
  • RE: VBA : how to concatene a list of mails from a form
    ... "PHil" wrote: ... now the button is in the top of the sub form, maybe I should put in the main ... provides your list of students for the lesson. ... The code you have is for a listbox, it loops through and checks which items ...
    (microsoft.public.access.modulesdaovba)