[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Listview Items and scrolling issues when promoting and demoting items.

Posted on 2007-03-29
2
Medium Priority
?
211 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

873 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