Click here to Skip to main content
15,901,122 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all ,
i have a listview control which populates dyanamically .Now whenever I click on any item i should be able to get the index of the item .. how can i do it ..

thnx ,
Posted
Comments
Raju Prajapati 16-Aug-11 6:01am    
On which you are working asp.net or window application
iampradeepsharma 16-Aug-11 6:09am    
windows application
Sergey Alexandrovich Kryukov 14-Mar-13 23:07pm    
Please don't post non-answers as "solution". It can give you abuse reports which eventually may lead to cancellation of your CodeProject membership.
Comment on any posts, reply to available comments, or use "Improve question" (above).
Also, keep in mind that members only get notifications on the post sent in reply to there posts.
—SA
iampradeepsharma 15-Mar-13 0:44am    
okay SA
Sergey Alexandrovich Kryukov 15-Mar-13 9:26am    
Thank you for understanding.
—SA

 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 15-Mar-13 9:31am    
Sure, a 5.
—SA
Did you read the documentation (ListView.SelectItems[^])?
 
Share this answer
 
Comments
Coder Block 16-Aug-11 6:01am    
Hi have seen my question?
I really espected some trick fro you.
Sergey Alexandrovich Kryukov 15-Mar-13 9:29am    
You want some trick? I'll tell you the trick: called RTFM ("Read The Following Manual", the one referenced above). As I can see, it will be tricky enough for you, but it will solve your problem if performed completely.
—SA
Sergey Alexandrovich Kryukov 15-Mar-13 9:30am    
5ed, accordingly... :-)
—SA
Handle the SelectedIndexChanged event of your ListBox:
C#
private void myListBox_SelectedIndexChanged(object sender, EventArgs e)
    {
    ListBox lb = sender as ListBox;
    if (lb != null)
        {
        int index = lb.SelectedIndex;
        Console.WriteLine(index);
        }
    }
This will only work if the SelectionMode is One: for Multi selection listboxes you need to look at the SelectedIndexes list instead.
 
Share this answer
 
use ListView1.SelectedIndex

it will work :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900