c# checked list box help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • LLM
    New Member
    • Apr 2007
    • 23

    #1

    c# checked list box help

    Ok I fill a CheckedListBox this way


    clbRoles.DataSo urce = objSecurity.Ret urnRoleList();
    clbRoles.Displa yMember = "RoleName";
    clbRoles.ValueM ember = "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.SetIte mChecked(x, objSecurity.Ans werUserHasRole( 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.Get ItemCheckState( i) == CheckState.Chec ked)
    {
    objSecurity.Add UserRole(strUse rID, clbRoles.Select edValue.ToStrin g());
    }
    else
    {
    //objSecurity.Del eteUserRole(str UserID, clbRoles.Select edValue.ToStrin g());
    objSecurity.Del eteUserRole(str UserID, clbRoles.Items[i].ToString());
    }
    }
Working...