本文介绍了如何从检查的CheckedListBox项的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了一个以上的CheckedListBox我在C#WinForm的。我已经有界的这种控制如下 -

I have used a CheckedListBox over my WinForm in C#. I have bounded this control as shown below -

chlCompanies.DataSource = dsCompanies.Tables[0];
chlCompanies.DisplayMember = "CompanyName";
chlCompanies.ValueMember = "ID";



我可以检查的项目的索引,但我怎样才能得到检查项目的文本和值。而如何我可以通过CheckedItems访问Text和Value枚举?

I can get the indices of checked items, but how can i get checked item text and value. Rather how can i enumerate through CheckedItems accessing Text and Value?

感谢您分享您的时间。

推荐答案

在相应的栏目将它转换回原来的类型,这将是一个DataRowView的,如果你绑定一个表,然后就可以得到Id和文字:

Cast it back to its original type, which will be a DataRowView if you're binding a table, and you can then get the Id and Text from the appropriate columns:

foreach(object itemChecked in checkedListBox1.CheckedItems)
{
     DataRowView castedItem = itemChecked as DataRowView;
     string comapnyName = castedItem["CompanyName"];
     int? id = castedItem["ID"];
}

这篇关于如何从检查的CheckedListBox项的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 04:43