How to prevent ListBox.SelectedIndexChanged event?

后端 未结 7 1470
时光说笑
时光说笑 2020-12-16 11:37

I am using a listbox in my C#2.0 windows forms application. The method to populate the list box is

    private void PopulateListBox(ListBox lb, ReportColum         


        
7条回答
  •  情话喂你
    2020-12-16 12:14

    There are three ways you can go about this.

    A) Don't hook into the SelectedIndexChanged event until AFTER you've called this method.

    B) Have a private boolean in your class that's initially set to true. At the start of your PopulateListBoxmethod, set it to false, and at the end set it back to true. In your event handler for SelectedIndexChanged , if the flag is false, just return and do nothing.

    C) In the start of your PopulateListBoxmethod, unhook from the event (this.listbox1.SelectedIndexChanged -= myMethod;) and then right before the method is done, rehook into that event.

提交回复
热议问题