![](/img/trans.png)
[英]In a combobox, how do I determine the highlighted item (not selected item)?
[英]How do I set selected item in a combobox class?
我已經用list類填充了一個組合框。
cboParentMenu.DataSource = listMenu;
cboParentMenu.DisplayMember = "caption";
這是類變量。
public string caption { get; set; }
public string caption_style { get; set; }
public string cat_id { get; set; }
public int id_menu { get; set; }
現在,如何使用字段id_menu設置所選項目? 我在想這樣的事情。
cboParentMenu.SelectedItem.id_menu = 123;
你可以做
cboParentMenu.SelectedItem = listMenu.FirstOrDefault(x => x.id_menu == 123);
確保導入System.Linq
。
嘗試這個:
cboParentMenu.SelectedValue = listMenu.Find(i => i.id_menu == 123);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.