At the moment, I’m learning towards win development. I got a very simple problem which is “Removing checked item on checked box list”. The first code below is throwing an error since you try to delete an item then on the postback it will reset the index. The real solution is on the second code
//this code is throwing an error about the index position private void btnRemove_Click(object sender, EventArgs e) { foreach (SMSData item in chkSmsList.CheckedItems) { chkSmsList.Items.Remove(item); } }
Fix
//this is the code which is working perfectly, basically this code always looking into the first item on the "CheckedItems" Stack private void btnRemove_Click(object sender, EventArgs e) { while (chkSmsList.CheckedItems.Count > 0) { chkSmsList.Items.Remove(chkSmsList.CheckedItems[0]); } }