Solved

Currently Selected item in ListView

Posted on 2009-04-07
6
326 Views
Last Modified: 2012-05-06
How could i get the index of   currently selected item in a listview if mulple selection is allowed.
0
Comment
Question by:replyanshu
  • 2
  • 2
6 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 24088599
Usually there is a collection of "selected indices".

For example, in VB.Net:

        For i As Integer = 0 To ListView1.SelectedIndices.Count - 1
            Dim index As Integer = ListView1.SelectedIndices(i)
            Dim lvi As ListViewItem = ListView1.Items(index)
        Next

You could also access the items directly:

        For Each lvi As ListView In ListView1.SelectedItems
            ' ...do something with "lvi"...
        Next
0
 

Author Comment

by:replyanshu
ID: 24137594
I got Solution for my self I had develop a function which return the currently selected index:

 Private Function FindIndex() As Integer
        Dim intSelIndex As Integer
              If Me.lv_LineItem.lvDisplay.SelectedItems.Count = 1 Then
            m_ValueofZerothIndex = Me.lv_LineItem.lvDisplay.SelectedIndices.Item(0)
            intSelIndex = 0
        Else
            If m_ValueofZerothIndex = Me.lv_LineItem.lvDisplay.SelectedIndices.Item(0) Then
                m_ValueofZerothIndex = Me.lv_LineItem.lvDisplay.SelectedIndices.Item(0)
                intSelIndex = Me.lv_LineItem.lvDisplay.SelectedItems.Count - 1
            Else
                m_ValueofZerothIndex = Me.lv_LineItem.lvDisplay.SelectedIndices.Item(0)
                intSelIndex = 0
            End If
        End If
        Return intSelIndex
    End Function
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 24139201
...I showed you how to use the SelectedIndices() property over seven days ago!...   =\
0
 

Author Comment

by:replyanshu
ID: 24144577
Yes but i  get this even before than this from google.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

821 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