Solved

See bottom item of listview automatically as new items are added

Posted on 2007-03-29
8
252 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

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

PBLack
0
 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 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