Tag: valuemember

使用C#从ListBox中的选定项获取ValueMember

我正试图从带有C#的ListBox中获取所有选定的项目ValueMember。 例如: 我有一个这样的列表: ID | Name and Lastname ———————- 1 | John Something 2 | Peter Something2 3 | Mary Smith 这个结构是我的ListBox的一部分。 我用这段代码构建了这个列表框: private void fill_people_listBox() { this.listBoxPeople.DataSource = db.query(“SELECT ….”); this.listBoxPeople.DisplayMember = “people_name_last”; this.listBoxPeople.ValueMember = “people_id”; } ListBox已成功填充。 当用户想要保存更改时,我将遍历此列表以获取所有选定的项目,但我不需要该项目,我需要ID。 例: 1 | John Something. 忽略John Something,得1,所以我不需要DisplayMember,只需要ValueMember。 为此,我尝试了以下几种方法: 1º foreach (ListBox selectedItem in this.listBoxGarantes.SelectedItems) { […]