How to insert 'Empty' field in ComboBox bound to DataTable

后端 未结 13 1448
谎友^
谎友^ 2020-12-14 09:07

I have a combo box on a WinForms app in which an item may be selected, but it is not mandatory. I therefore need an \'Empty\' first item to indicate that no value has been s

13条回答
  •  感动是毒
    2020-12-14 09:28

    I had a similar challenge. As part of the form load event I set the SelectedIndex of the control to -1

    ie

    private void Form1_Load(object sender, EventArgs e)
    {         
        this.TableAdapter.Fill(this.dsListOfCampaigns.EvolveCampaignTargetListMasterInfo);
        this.comboCampaignID.SelectedIndex = -1;
    }
    

    Effectively, the combo box is populated and the first item is selected. Then the item is unselected. May not be a viable solution for all cases.

提交回复
热议问题