Solved

Currently Selected item in ListView

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now