Search code examples
c#listboxlistbox-control

Adding checkbox controls to list box


I'm new to .NET environment and just a student. I'm working on User Management. I want to assign multiple roles to one user. For this purpose I've created list box which contains a list of roles from database.

 lbRoles.Items.Add(readerRole["RoleName"].ToString());

I just need a check box with each item. Please suggest how to add a checkbox with each item. I did tried

lbRoles.Controls.Add(checkBox);
lbRoles.Items.Add(readerRole["RoleName"].ToString());

But it was not helpful. I did google but no result :(


Solution

  • There is the CheckedListBox class, its very simple and does exactly what you want. :)

    Displays a ListBox in which a check box is displayed to the left of each item.