views:

487

answers:

5

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.

+3  A: 

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.

Jon Seigel
+1 for refactoring the gui.
Rob Allen
+1  A: 

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.

Terry_Brown
Yes , I would like to make a dropdown list populated with comboboxes , like the filter dialog in excel 2007.Buy it is kinda useless, the whole point of my app is to practice and learn to do some things in vb.net
Iulian
I tend to work in the asp.net world, but the following were found with a google search - perhaps some of them will have code that can help you in learning, in particular that first thread on SO looks a good one:http://stackoverflow.com/questions/859227/looking-for-a-wpf-combobox-with-checkboxeshttp://wpfcolorpicker.codeplex.com/http://blogs.msdn.com/llobo/archive/2006/10/25/Split-Button-in-WPF.aspxhttp://www.eggheadcafe.com/tutorials/aspnet/e8585e81-34c8-4808-ae3e-b8b35d738842/wpf-datagrid-as-combobox.aspx
Terry_Brown
A: 

I have found a CodeProject article on how to do it (more like "already made" but at least i can poke around the code and learn how he did it) I don't know how I've missed that earlier.

Here is the link .

Iulian
A: 

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:

  1. 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).

  2. 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).

Larry Lustig
Using this kind of approach (note: not necessarily recommended), I would stick with the drop down list, but when the drop down part opens, overlay a check box list.
Jon Seigel
that is a very good idea , thanks a lot
Iulian
A: 

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

hground