Solved

See bottom item of listview automatically as new items are added

Posted on 2007-03-29
8
243 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
how would I do that? I am a relative newbie to this

PBLack
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:PBLack
Comment Utility
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
Comment Utility
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
Comment Utility
The last one's fine

Roger
0
 

Author Comment

by:PBLack
Comment Utility
thanks for all of the help

PBLack
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

9 Experts available now in Live!

Get 1:1 Help Now