简体   繁体   中英

How to clear combobox value in the windows form using c#?

I am building an windows application..So in my combobox i have 2 feilds "familyHead" and "familyMember" so based up on the user selection i want to show the records.Suppose if he select familyHead then i will show familyHead details i am providing first,last,next,clear buttons.

so i captured combobox value like below:

 position = this.cbPosition.GetItemText(this.cbPosition.SelectedItem);

so now,i got the position so if the user not selected the position.Then i will show the message please select the position.So everything is fine.

But, the problem here is when the user click on the clear button.After that he click on First button on the form,It is not asked please select the position, directly displays the details on the form based on previous value.

Under clear button:

I removed postion and also text of the combobox like below:

position = "";
cbPosition.Text = "";

Thanks

我会说你应该将选定的索引设置为 -1,或者类似的东西

cbPosition.SelectedIndex = -1;

您可能需要考虑向组合框添加一个“空白项目”,以便用户始终可以清除他的选择

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM