简体   繁体   English

在项目单击上显示CheckedListBox的ValueMember

[英]Show ValueMember of CheckedListBox on item click

I have a winform c# checkedlist box. 我有一个Winform C#清单框。 This checklist box is Databound. 此清单框是“数据绑定”。 It's Display Member contains names of student and valueMember contains their ID's. 它的显示成员包含学生的姓名,valueMember包含其ID。 From the checklistbox, when I check any item, I want it to show their corresponding ID as present in ValueMember. 从复选框中,当我检查任何项目时,我希望它显示ValueMember中存在的相应ID。 At present in the ItemCheck event. 目前在ItemCheck事件中。 I am iterating all the checked items and showing their ValueMember. 我正在迭代所有选中的项目并显示其ValueMember。

Is it possible to get the ValueMember property without iterating through the list? 是否可以在不迭代列表的情况下获取ValueMember属性? I would prefer a one or two line solution. 我希望使用一两个解决方案。

foreach (DataRowView view in chkLBoxNames.CheckedItems)
{
  MessageBox.Show(view[chkLBoxNames.ValueMember].ToString());
} 

I do not know how to write this solution without sounding like a commercial, but try the free trial of Resharper. 我不知道如何写这种解决方案而不听起来像是商业广告,但是请尝试Resharper的免费试用。 You will get exactly what you are looking for. 您将得到您真正想要的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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