BradSmith1985 / DropDownControls

Drop-Down Controls for .NET
50 stars 34 forks source link

GroupedComboBox not grouping in VB #11

Closed CArrandale closed 1 year ago

CArrandale commented 1 year ago

Hello.

I have added devmaestro1's project fork to a test project. I'm using VB .NET Framework 4.8. I can add the controls from the designer although the groups in the grouped combo box don't seem to be working. I've taken a look at the demo's and they're all in C# so I'm just a little unsure if something has gotten lost in translation. Thank you!

Dim groupedItems = New Object() {New With {.Group = "Group 1", .Value = 1, .Display = "Test", .ToolTip = "More info 1"},
    New With {.Group = "Group 1", .Value = 2, .Display = "Test 2", .ToolTip = "More info 2"},
    New With {.Group = "Group 2", .Value = 3, .Display = "Test 3", .ToolTip = "More info 3"}}

GroupedComboBox1.ValueMember = "Value"
GroupedComboBox1.DisplayMember = "Display"
GroupedComboBox1.GroupMember = "Group"

GroupedComboBox1.DataSource = New BindingSource(groupedItems, String.Empty)

Produces:

image

CArrandale commented 1 year ago

Not even 10 minutes after posting I figured it out. I'm going to post the solution here for anyone who happens to stumble upon it later. The binding source needs to be a list and not an array.

Dim groupedList As New List(Of Object) From {
    New With {.Group = "Group 1", .Value = 1, .Display = "Test", .ToolTip = "More info 1"},
    New With {.Group = "Group 1", .Value = 2, .Display = "Test 2", .ToolTip = "More info 2"},
    New With {.Group = "Group 2", .Value = 3, .Display = "Test 3", .ToolTip = "More info 3"}
}

GroupedComboBox1.ValueMember = "Value"
GroupedComboBox1.DisplayMember = "Display"
GroupedComboBox1.GroupMember = "Group"

GroupedComboBox1.DataSource = New BindingSource(groupedList, String.Empty)