Solved

Currently Selected item in ListView

Posted on 2009-04-07
6
324 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

777 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