How to prevent ListBox.SelectedIndexChanged event?

后端 未结 7 1475
时光说笑
时光说笑 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-16 12:02

    There is a simplest answer to this problem: A Code snippet below can suggest the work around.

    lstBxState.SelectionMode = SelectionMode.None;
    lstBxState.DataSource = lstStates;
    lstBxState.ValueMember = "StateId";
    lstBxState.DisplayMember = "StateName";
    lstBxState.ClearSelected();
    lstBxState.SelectionMode = SelectionMode.One;
    

    This means, just Make the Selection Mode as "None", and happily Data Bind the control. Then go ahead and change the mode to the required one (Here I have changed it to One, you may select Multiple too).

提交回复
热议问题