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 :(
The label control is used to display a text or a message to the user on the form. The label control is normally used along with other controls. Common examples is wherein a label is added along with the textbox control. The label gives an indication to the user on what is expected to fill up in the textbox.
It's identical to the ListBox control, but a check box appears in front of each item. The user can select any number of items by selecting the check boxes in front of them. As you know, you can also select multiple items from a ListBox control by pressing the Shift and Ctrl keys.
There is the CheckedListBox class, its very simple and does exactly what you wants. :)
Displays a ListBox in which a check box is displayed to the left of each item.
Instead of using a ListBox, use a ListView instead and set ListView.Checkboxes to true.
This will place a CheckBox next to each item in the ListView, and your users can select specific items in the ListView by clicking the checkboxes, then get the selected items using ListView.SelectedItems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With