How to prevent ListBox.SelectedIndexChanged event?

后端 未结 7 1459
时光说笑
时光说笑 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:15
    private void PopulateListBox(ListBox lb, ReportColumnList reportColumnList)
    {
    
        lb.SelectedIndexChanged -= this.*MethodnamewhichhandlesthisEvent*;  //unset eventhandler
    
        lb.DataSource = reportColumnList.ReportColumns;
        lb.DisplayMember = "ColumnName";
        lb.ValueMember = "ColumnName";
    
        lb.SelectedIndexChanged += this.*MethodnamewhichhandlesthisEvent*;  //set the eventhandler
    }
    

    Basically remove the delegate from the event and then add once you are done.

    0 讨论(0)
提交回复
热议问题