Remove item from ComboBox (DropDownList) Winforms

前端 未结 1 1232
生来不讨喜
生来不讨喜 2021-01-14 06:25

I have a dropdownlist which has been populated

ddlNumbers.DisplayMember = \"PhoneNumber\";
ddlNumbers.DataSource = mobileList;
ddlNumbers.SelectedItem = null         


        
相关标签:
1条回答
  • 2021-01-14 07:19

    You can't remove an item from a list when its bound to a control, You can temporarily null the data source of the bound control and remove the item from list and then set the data source again.

    Something like,

    //Null the datasource
    Combobox1.Datasource = null;
    
    //Remove the item
    ddlMobileNumbers.Items.RemoveAt(i);
    
    //Set the source again
    Combobox1.Datasource = ddlMobileNumbers;
    
    0 讨论(0)
提交回复
热议问题