Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Currently Selected item in ListView

Posted on 2009-04-07
6
Medium Priority
?
350 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
[X]
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
  • 2
  • 2
6 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 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 86

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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

609 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