Add Selected Rows to RadMultiColumnComboBox with Multi-Select Extender

1 Answer 293 Views
MultiColumn ComboBox
Alex
Top achievements
Rank 1
Alex asked on 06 Dec 2021, 02:35 PM | edited on 06 Dec 2021, 02:36 PM

I created an unbound MultiColumnComboBox and added the multi-select functionality from the how-to documentation. This works fine, but I'd now like to add some rows and set them as selected when the form loads up based on some text input. So I have gone with the below:

Imports Telerik.WinControls.UI

Public Class Form1
    Private Extender As New RadMultiColumnComboBoxSelectionExtender
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        InitCombo()

        Extender = New RadMultiColumnComboBoxSelectionExtender()
        Extender.AssociatedRadMultiColumnComboBox = combo1

        AddExtraItems()
    End Sub

    Private Sub InitCombo()
        combo1.MultiColumnComboBoxElement.Columns.Add("CaseCode")
        combo1.MultiColumnComboBoxElement.Columns.Add("Title")
        combo1.DisplayMember = "CaseCode"
        combo1.ValueMember = "CaseCode"

        combo1.EditorControl.Rows.Add("P1234", "Test Case 1")
        combo1.EditorControl.Rows.Add("A1234", "Test Case 2")
    End Sub

    Private Sub AddExtraItems()
        AddRow("T12345", "Test Case 3", True)
        AddRow("P23445", "Test Case 4", True)
    End Sub

    Private Sub AddRow(ByVal CaseCodeString As String, ByVal Title As String, Optional ByVal Pinned As Boolean = False)
        Dim row = combo1.EditorControl.Rows.NewRow()
        row.Cells(0).Value = CaseCodeString
        row.Cells(1).Value = Title

        If Pinned Then
            row.PinPosition = PinnedRowPosition.Top
            row.IsSelected = True
            row.Tag = True
        End If

        combo1.EditorControl.Rows.Add(row)
    End Sub

    Private Sub combo1_DropDownClosing(sender As Object, args As RadPopupClosingEventArgs) Handles combo1.DropDownClosing
        args.Cancel = True
    End Sub
End Class

This adds items to the list and has them ticked however items do not appear as tokens in the Combobox and if I open the combobox and tick/untick an item the application crashes and the form closes. Is there a specific way to do this? I have attached a small example project to demo what is happening.

Thanks in advance for any help!

1 Answer, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 07 Dec 2021, 08:45 AM

Hello, Alex, 
I suppose that you are referring to this documentation article:
https://docs.telerik.com/devtools/winforms/controls/multicolumncombobox/how-to/multiple-selection

However, after running the provided project and trying to check the last row, I encountered the following error:

This approach with RadMultiColumnComboBox is preferably to be used in bound mode:

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' InitCombo()

        Dim dt As New DataTable
        dt.Columns.Add("CaseCode")
        dt.Columns.Add("Title")
        dt.Rows.Add("P1234", "Test Case 1")
        dt.Rows.Add("A1234", "Test Case 2")
        Me.combo1.DisplayMember = "Title"
        Me.combo1.ValueMember = "CaseCode"
        Me.combo1.DataSource = dt

        Extender = New RadMultiColumnComboBoxSelectionExtender()
        Extender.AssociatedRadMultiColumnComboBox = combo1

        dt.Rows.Add("T12345", "Test Case 3")
        dt.Rows.Add("P23445", "Test Case 4")

        ' AddExtraItems()
    End Sub

Then, if you need to add new records to the applied DataSource, it is necessary to ensure that the extender will be properly refreshed with the new rows. The RadMultiColumnComboBoxSelectionExtender.AutoCompleteBoxElement.Text property allows you to manage the tokens:

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' InitCombo()

        Dim dt As New DataTable
        dt.Columns.Add("CaseCode")
        dt.Columns.Add("Title")
        dt.Rows.Add("P1234", "Test Case 1")
        dt.Rows.Add("A1234", "Test Case 2")
        Me.combo1.DisplayMember = "Title"
        Me.combo1.ValueMember = "CaseCode"
        Me.combo1.DataSource = dt

        Extender = New RadMultiColumnComboBoxSelectionExtender()
        Extender.AssociatedRadMultiColumnComboBox = combo1

        'add new records to the DataSource and make sure that the extender will be properly refreshed with the new rows
        Extender.AssociatedRadMultiColumnComboBox = Nothing
        dt.Rows.Add("T12345", "Test Case 3")
        dt.Rows.Add("P23445", "Test Case 4")
        Extender.AssociatedRadMultiColumnComboBox = combo1

        Extender.AutoCompleteBoxElement.Text = "Test Case 3;"

        ' AddExtraItems()
    End Sub

Off topic, I would like to note that Telerik UI for WinForms suite offers a control that provides functionality to check multiple items in the drop down area and tokenize them in the text area. It is called RadCheckedDropDownList. However, similar to RadDropDownList, it displays just a single field for each item controlled by the DisplayMember. This tutorial demonstrates a sample approach how to achieve checked RadMultiColumnComboBox - show several columns of data whilst being able to select multiple items with check boxes without closing the popup:

https://docs.telerik.com/devtools/winforms/knowledge-base/checked-multicolumncombobox 

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Alex
Top achievements
Rank 1
commented on 07 Dec 2021, 11:04 AM

Hi Dess,

Thanks for the swift and helpful reply! I have actually switched to using the RadCheckedDropDownList now as I only needed one detail to be displayed and the description works fine for this. The referenced article for checked-multicolumncombobox is also very useful so i'll bear this in mind if I need to add extra columns in.

Tags
MultiColumn ComboBox
Asked by
Alex
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or