470,641 Members | 1,592 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,641 developers. It's quick & easy.

c# checked list box help

23
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());
}
}
Apr 30 '07 #1
0 2347

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

26 posts views Thread by Simon Jefferies | last post: by
reply views Thread by adam | last post: by
3 posts views Thread by Rob | last post: by
2 posts views Thread by rishabhshrivastava | last post: by
2 posts views Thread by Aaron Reimann | last post: by
2 posts views Thread by saurabhnsit2002 | last post: by
1 post views Thread by Korara | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.