Solved

Listview Items and scrolling issues when promoting and demoting items.

Posted on 2007-03-29
2
198 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

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

932 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

11 Experts available now in Live!

Get 1:1 Help Now