How can i make a dropdown list with checkboxes ? I have a windows app ( vb.net) and the checkboxlist control is not real an option with the available space on my form.
Thanks.
How can i make a dropdown list with checkboxes ? I have a windows app ( vb.net) and the checkboxlist control is not real an option with the available space on my form.
Thanks.
You'd have to go owner-drawn to get that kind of functionality.
If your form is out of space, I would suggest first looking to see if you can refactor the GUI to make it simpler.
I suspect your question may well be edited as it's not very clear at present. I'm guessing you want a dropdown list control on the form, but when the list drops down you have checkboxes as the options within it? If so, I suspect you may be looking at a custom set of controls (the Telerik controls will allow you to template a RadComboBox for example), but I don't think there are any standard controls that will allow this.
The easiest way to create this effect is to use three controls — an edit, a button (to the right of the edit, with a drop down icon) and a checkboxlist as you're using now.
Position the checkboxlist under the edit so its width is the same as the edit and the button next to the edit, and make it invisible. Now, add code to the button to:
Make the checklistbox visible if it is not visible and to make it not visible if it is visible (that is, flip the value of .Visible).
Call code to create a "summarized" version of what was checked and not check and display it in the edit. For instance, if your "dropdown" contains color names, you might have your code create a comma-delimited list of the checked colors and display that in the edit.
You can take this a little further and put the checkboxlist into a panel container and add little buttons to the "dropdown" to execute whatever special functions might be appropriate in your application (check all, uncheck all, whatever).
I found a simpler solution and thought I would post it if anyone searching like I was could use it. What I did was insert a single-column Listview onto my form with View set to Detail mode, MultiSelect set to True, and Checkboxes set to True. The following code will allow the list to drop down. Since I have multi-selection there is no need to display the selected value like you would do in a combo box so the drop-down appears to be a button to Show/Hide the list. In the code below I am dividing the height by 4 because my list is static and that is how many check boxes I have in my list. If you have a dynamic list then just read the number of items from the Listview and use that. You may have to play with it some to get the appearance that you want. Here are the events that I use:
Dim iListHt As Integer 'Set global variable to save height of list
'Save initial height of list and then collapse it to a button
iListHt = lvList.Height
lvList.Height = CInt(iListHt / 4)
lvList.Columns(0).Text = "Display List"
Private Sub lvList_ColumnClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles lvList.ColumnClick
Dim iHt As Integer = lvList.Height
If (iHt < iListHt) Then
lvList.Height = iListHt
lvList.Columns(0).Text = "Hide List"
Else
lvList.Height = CInt(iHt / 4)
lvList.Columns(0).Text = "Display List"
End If
lvList.Refresh()
End Sub
Private Sub lvList_ItemChecked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckedEventArgs) Handles lvList.ItemChecked
'Read values from list check boxes and update settings
UpdateSettings()
End Sub
The ColumnClick event handles when they click on what looks like the Show/Hide List button and the ItemChecked event lets me handle anything that needs to respond to a change in the checkboxes. The value of each is read by accessing the "lvList.Items(iRowNum).Checked" value where iRowNum is the row you want to check. Hope this helps the next person that needs something like this.
hground