Solved

See bottom item of listview automatically as new items are added

Posted on 2007-03-29
8
261 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

635 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