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
Solved

Listview Items and scrolling issues when promoting and demoting items.

Posted on 2007-03-29
2
201 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 Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 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