Link to home
Start Free TrialLog in
Avatar of Todd MacPherson
Todd MacPhersonFlag for Canada

asked on

See bottom item of listview automatically as new items are added

Hi

I have a problem I do not know how to solve. After a user adds enough items to a listview causing the vertical scrollbar to appear, the bottom (or most recently added item) is not displayed unless the user scrolls down manually. Is there anyway to make it display the bottom item automatically after it is added to the listview?

Thanks

PBLack
- PS I have another question of a similar nature involving promoting and/or demoting items in a listview
see https://www.experts-exchange.com/questions/22479630/Listview-Items-and-scrolling-issues-when-promoting-and-demoting-items.html

        Dim Xsub As String = (lstMenu.Items.Count + 1).ToString
        Dim lstAttItem As ListViewItem = New ListViewItem(Xsub)
        Dim lvDup As ListViewItem
        Dim blnDuplicate As Boolean

        For Each lvDup In lstMenu.Items
            If UCase(Trim(lvDup.SubItems(1).Text)) = UCase(Trim(txtName.Text)) OrElse (UCase(txtCode1.Text.Trim) = Trim(lvDup.SubItems(2).Text) And UCase(txtCode1.Text.Trim) <> "0") Then 'OrElse UCase(txtCode2.Text.Trim) = lvDup.SubItems(2).Text Then
                Beep()
                MsgBox("Duplicate entries are not permitted in Value or Code 1 columns. Please fix.", MsgBoxStyle.Information)
                txtName.Focus()
                blnDuplicate = True
                Exit For
            End If
        Next

        If Not blnDuplicate Then
            Beep()
            lstMenu.Items.Add(lstAttItem)
            'lstAttItem.SubItems.Add(sub1Pad)
            'lstAttItem.SubItems.Add(sub2Pad)
            'lstAttItem.SubItems.Add(sub3Pad)
            lstAttItem.SubItems.Add(Trim(txtName.Text))
            lstAttItem.SubItems.Add(Trim(txtCode1.Text))
            lstAttItem.SubItems.Add(Trim(txtCode2.Text))
        End If
ASKER CERTIFIED SOLUTION
Avatar of Sancler
Sancler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Todd MacPherson

ASKER

added:

            Dim i As Integer
            For i = 0 To lstMenu.Items.Count - 1
                lstMenu.Items(i).EnsureVisible()
            Next

to routine

Thanks
Avatar of Sancler
Sancler

Thanks for the points.  You really only need to call the method on the single item - the last one added, or the moved one that has been reinserted - rather than on all of them.

Roger
how would I do that? I am a relative newbie to this

PBLack
I switched it to this:

            Dim i As Integer
            i = lstMenu.Items.Count - 1
            lstMenu.Items(i).EnsureVisible(

Is that better?

PBLack
oops

            Dim i As Integer
            i = lstMenu.Items.Count - 1
            lstMenu.Items(i).EnsureVisible()

Missed the closing bracket
The last one's fine

Roger
thanks for all of the help

PBLack