简体   繁体   中英

get CheckedItems from checkedlistbox

i have checkedlistbox which is bounded to a datasource as foloowing :

     chListBox.DataSource = dsContacts.Tables["Contacts"];
     chListBox.DisplayMember = "FullName";
     chListBox.ValueMember = "ContactNumber";

i want to get checkeditems collection by following code , but 'Unable to cast object of type 'System.Data.DataRowView' to type 'System.String' ' error occurs . :

        int i = 0;
        foreach (string row in chListBox.CheckedItems)
        {
            phoneNumbers[i] = row.ToString();
            i++;
        }

what is the problem ?

The contents of CheckedItems isn't strings.

    int i = 0; 
    foreach (DataRowView rowView in chListBox.CheckedItems) 
    { 
        phoneNumbers[i] = rowView["ContactNumber"]; 
        i++; 
    } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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