Ok I fill a CheckedListBox this way
clbRoles.DataSource = objSecurity.ReturnRoleList();
clbRoles.DisplayMember = "RoleName";
clbRoles.ValueMember = "RoleID";
#1 Issue: I want to select certain items in those list for roles the user already has. I tried the following but the last part doesn't work. How do I get the ID of the item as I am looping through?
for (int x = 0; x <= clbRoles.Items.Count; x++)
{
clbRoles.SetItemChecked(x, objSecurity.AnswerUserHasRole(strUserID, clbRoles.Items[x].ToString()));
}
#2 Issue: I want to then loop through each one again and do something for all the checked and do something for all the not checked ones. I am trying but again I can't seem to get the id from the item as I am looping, How do I get the ID??
for (int i=0; i< clbRoles.Items.Count; i++)
{
if(clbRoles.GetItemCheckState(i) == CheckState.Checked)
{
objSecurity.AddUserRole(strUserID, clbRoles.SelectedValue.ToString());
}
else
{
//objSecurity.DeleteUserRole(strUserID, clbRoles.SelectedValue.ToString());
objSecurity.DeleteUserRole(strUserID, clbRoles.Items[i].ToString());
}
}