Reputation: 2126
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 ?
Upvotes: 0
Views: 7402
Reputation: 837996
The contents of CheckedItems isn't strings.
int i = 0;
foreach (DataRowView rowView in chListBox.CheckedItems)
{
phoneNumbers[i] = rowView["ContactNumber"];
i++;
}
Upvotes: 3