简体   繁体   English

c#如何获取列表框中的选定项目是否已更改。 ?

[英]c# how do i get check if a selected item in a listbox has changed. ?

i understand listbox.selectedItem will get me the current item thats seletected in a listbox... how do i get if the current item has been changed. 我了解listbox.selectedItem将为我提供在列表框中分离出的当前项目...如果当前项目已更改,我如何获得。 so i want to know if the user's selection has changed from what it was to a different item. 所以我想知道用户的选择是否已从原来的更改为其他项目。

Subscribe to the SelectedIndexChanged event like this: 订阅SelectedIndexChanged事件,如下所示:

this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);

The listener is: 侦听器是:

    private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

Add code in the listener above to react to the event. 在上面的侦听器中添加代码以对该事件做出反应。

您自然可以监听SelectedIndexChanged事件,这是Windows.Forms

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM