[英]C# combobox dropdown
我希望我的組合框在按下文本框和下拉符號時下拉
我已經做到了:
private void comboBoxOpretKomponentLevel_Enter(object sender, EventArgs e)
{
if (comboBoxOpretKomponentLevel.SelectedIndex <= 0)
{
comboBoxOpretKomponentLevel.Text = null;
}
comboBoxOpretKomponentLevel.Focus();
comboBoxOpretKomponentLevel.DroppedDown = true;
}
如果選擇了文本(“選擇產品”),則.Droppeddown = true使其起作用。但是,當按下dropbox的下拉符號時-下拉菜單再次變為false。 我該如何工作? 據我所知,我不能使用DropDownList,因為我沒有我的(“選擇產品”)文本。
我只是使用MouseClick
事件。 由於您的問題過於廣泛,所以我只有這段代碼可能會對您有所幫助。
它的作用是,僅當您click
ComboBox
或與此ComboBox
有關的任何控制器時,它才會打開dropdownlist
。 要關閉它,只需click
Form_Load
事件,它將使dropdownlist
空閑
private void comboBoxOpretKomponentLevel_MouseClick(object sender, MouseEventArgs e)
{
//This piece will dropdown the combobox once you click it.
comboBoxOpretKomponentLevel.DroppedDown = true;
comboBoxOpretKomponentLevel.Focus();
}
private void YourForm_Click (object sender, EventArgs e)
{
//This piece will simply close the dropdown from your combobox and use the selected value.
comboBoxOpretKomponentLevel.DroppedDown = false;
}
希望對您有所幫助,否則簡單地重新制定您的問題,以便我們為您提供幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.