Solved

See bottom item of listview automatically as new items are added

Posted on 2007-03-29
8
244 Views
Last Modified: 2010-05-18
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 http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_22479630.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
0
Comment
Question by:PBLack
  • 5
  • 3
8 Comments
 
LVL 34

Accepted Solution

by:
Sancler earned 500 total points
ID: 18814200
Check out the ListView.EnsureVisible Method.  See this

http://msdn2.microsoft.com/en-us/library/system.windows.forms.listview.ensurevisible.aspx

Roger
0
 

Author Comment

by:PBLack
ID: 18814270
added:

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

to routine

Thanks
0
 
LVL 34

Expert Comment

by:Sancler
ID: 18814358
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
0
 

Author Comment

by:PBLack
ID: 18814412
how would I do that? I am a relative newbie to this

PBLack
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:PBLack
ID: 18814426
I switched it to this:

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

Is that better?

PBLack
0
 

Author Comment

by:PBLack
ID: 18814430
oops

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

Missed the closing bracket
0
 
LVL 34

Expert Comment

by:Sancler
ID: 18814475
The last one's fine

Roger
0
 

Author Comment

by:PBLack
ID: 18814497
thanks for all of the help

PBLack
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now