我已经用列表类填充了一个组合框。
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
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句