How to get value of checked item from CheckedListB

2019-01-18 09:37发布

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";

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?

Thanks for sharing your time.

8条回答
Deceive 欺骗
2楼-- · 2019-01-18 10:03

You may try this :

string s = "";

foreach(DataRowView drv in checkedListBox1.CheckedItems)
{
    s += drv[0].ToString()+",";
}
s=s.TrimEnd(',');
查看更多
ら.Afraid
3楼-- · 2019-01-18 10:06

try:

  foreach (var item in chlCompanies.CheckedItems){
     item.Value //ID
     item.Text //CompanyName
  }
查看更多
登录 后发表回答