Solved

Listview Items and scrolling issues when promoting and demoting items.

Posted on 2007-03-29
2
197 Views
Last Modified: 2010-07-27
Hi

I have a problem I do not know how to solve. I have a couple of buttons where a user selecets items in a listview and clicks a button causing item to either promote or demote in the listview by one position per click. If the amount of items exceeds the listview height then a  vertical scrollbar is present, and herein lies the problem.

If the user, for example, promotes an item near the bottom of the listview, and it moves up far enough the user can no longer see it unless they manually scroll to it. Is there anyway to make sure that the selected item always stays in view no matter how many items are in the listview?

Thanks
PBLack

PS I have a similar question concerning scrolling issues at  http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_22479629.html

===============================================
PROMOTE CODE:

        If lstMenu.SelectedIndices.Count = 0 Then
            Beep()
            Exit Sub
        End If

        Dim lvi As ListViewItem = lstMenu.Items(lstMenu.SelectedIndices(0))
        Dim inx As Integer
        Dim temp As Integer
        temp = lstMenu.Items.IndexOf(lvi)
        If temp = 0 Then
            Beep()
            Exit Sub
        End If
        inx = temp - 1

        Dim x As Integer = (lstMenu.SelectedIndices.Count - 1)
        While x >= 0
            lstMenu.Items.RemoveAt(lstMenu.SelectedIndices(x))
            System.Math.Max(System.Threading.Interlocked.Decrement(x), x + 1)
        End While
        Beep()
        lstMenu.Items.Insert(inx, lvi)
=========================================

DEMOTE CODE:

        If lstMenu.SelectedIndices.Count = 0 Then
            Beep()
            Exit Sub
        End If

        Dim lvi As ListViewItem = lstMenu.Items(lstMenu.SelectedIndices(0))
        Dim inx As Integer
        Dim temp As Integer
        Dim Y As Integer
        temp = lstMenu.Items.IndexOf(lvi)
        Y = lstMenu.Items.Count
        If temp = Y - 1 Then
            Beep()
            Exit Sub
        End If
        inx = temp + 1

        Dim x As Integer = (lstMenu.SelectedIndices.Count - 1)
        While x >= 0
            lstMenu.Items.RemoveAt(lstMenu.SelectedIndices(x))
            System.Math.Max(System.Threading.Interlocked.Decrement(x), x + 1)
        End While
        Beep()
        lstMenu.Items.Insert(inx, lvi)

Thanks

PBLack
- PS I have another question of a similar nature involving adding items to a listview
0
Comment
Question by:PBLack
2 Comments
 
LVL 34

Accepted Solution

by:
Sancler earned 500 total points
ID: 18814199
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: 18814260
added lstMenu.Items(inx).EnsureVisible() to the bottom of each routine

Thanks
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
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…

760 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

19 Experts available now in Live!

Get 1:1 Help Now