Checking Items in a CheckedBoxList based on Database Data
<p>I have a CheckedListBox in my c# application that displays the existing items in the database. Now, for each supplier I want to check the items it supplies. Following is what I have done so far.</p>

<pre><code>string sel_supplied = "SELECT * FROM item_supplier WHERE supplier_id='" + hid_supid.Text + "'";
MySqlCommand cmd_supplied = new MySqlCommand(sel_supplied, Class_Connection.conn);

try
{
    MySqlDataReader rdr_supplied = cmd_supplied.ExecuteReader();

    while (rdr_supplied.Read())
    {
        MessageBox.Show("Item: " + rdr_supplied["item_id"]);
        int i=0;

        foreach (DataRowView row in chklist_items.Items)
        {                            
            //MessageBox.Show(row[chklist_items.ValueMember].ToString());
            if (row[chklist_items.ValueMember].ToString() == rdr_supplied["item_id"].ToString())
            {
                chklist_items.SetItemChecked(i, true);
            }
            i++;
        }                        
    }
    rdr_supplied.Close();
}
catch (MySqlException ex)
{
    MessageBox.Show(ex.Message);
}
</code></pre>

<p>But the code generating an exception saying that, the list is being changed (as being checked runtime) and enumerator cannot be used for changing list.</p>

<p>Any help is appreciated, please.</p>
