如何在列表视图控件中获取所选项目的索引 [英] how to get the index of the selected item in the listview control

查看:102
本文介绍了如何在列表视图控件中获取所选项目的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有一个列表视图控件,其中充满活力.现在,每当我单击任何项​​目时,我都应该能够获取该项目的索引..我该怎么做..

thnx,

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 ,

推荐答案

SelectedIndexChanged
中使用SelectedIndex 参考: http://msdn.microsoft.com/zh-我们/library/system.web.ui.webcontrols.listview.selectedindexchanged.aspx [

您是否已阅读文档(ListView.SelectItems [
Did you read the documentation (ListView.SelectItems[^])?


处理ListBox的SelectedIndexChanged事件:
Handle the SelectedIndexChanged event of your ListBox:
private void myListBox_SelectedIndexChanged(object sender, EventArgs e)
    {
    ListBox lb = sender as ListBox;
    if (lb != null)
        {
        int index = lb.SelectedIndex;
        Console.WriteLine(index);
        }
    }

仅在SelectionMode为One的情况下有效:对于多选列表框,您需要查看SelectedIndexes列表.

This will only work if the SelectionMode is One: for Multi selection listboxes you need to look at the SelectedIndexes list instead.


这篇关于如何在列表视图控件中获取所选项目的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆