TelerikDeveloper.com

TelerikDeveloper.com

DanielE 2/3/2013 3:48:46 PM

Telerik - Multicolumn Dropdown Usage Example

This article contains a code example on how to use the Telerik Multicolumn Dropdown control    


Imports Telerik.WinControls.UI
 
Public Class Form1
 
    Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        'set the datasource for the control
        BindCombo()
 
        'set the control value
        Me.ddlOrder.Text = "ORD124"
 
    End Sub
 
    Sub BindCombo()
        'tell the ddl not to autogenerate the columns, we'll do it.
        Me.ddlOrder.EditorControl.MasterTemplate.AutoGenerateColumns = False
 
        'populate the ddl
        Me.ddlOrder.DataSource = getData()
        Me.ddlOrder.ValueMember = "OrderNumber"
        Me.ddlOrder.DisplayMember = "OrderNumber"
        Me.ddlOrder.MultiColumnComboBoxElement.DropDownWidth = "250"
 
        'setup the columns
        Dim gridViewControl As RadGridView = Me.ddlOrder.EditorControl
        'this is our Telerik Grid class, documented here:
        Dim oTelerikGrid As New FPTelerikCommon.TelerikGrid
        gridViewControl.Columns.Add(oTelerikGrid.createGridViewTextBoxColumn("Order Number", "OrderNumber", 0, 100))
        gridViewControl.Columns.Add(oTelerikGrid.createGridViewTextBoxColumn("Doc Amount", "DocAmount", 0, 80))
        gridViewControl.Columns.Add(oTelerikGrid.createGridViewTextBoxColumn("OrderType", "OrderType", 0, 80))
 
        'the code above automatically sets the column widths, so this is kind of redundant.
        'we have the code here for documentation purposes
        For Each column As GridViewDataColumn In Me.ddlOrder.MultiColumnComboBoxElement.Columns
            column.BestFit()
        Next column
 
 
    End Sub
 
    Function getData() As DataTable
        Dim oDT As New DataTable
 
        'add the columns
        oDT.Columns.Add(New DataColumn("OrderNumber", System.Type.GetType("System.String")))
        oDT.Columns.Add(New DataColumn("DocAmount", System.Type.GetType("System.Double")))
        oDT.Columns.Add(New DataColumn("OrderType", System.Type.GetType("System.String")))
 
        'add rows
        oDT.Rows.Add("ORD123", 1.21, "Order")
        oDT.Rows.Add("ORD124", 1.22, "Order")
        oDT.Rows.Add("RTN125", 1.23, "Return")
 
        Return oDT
 
    End Function
 
    Private Sub ddlOrder_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles ddlOrder.SelectedIndexChanged
        'the selected index of the ddl has changed.
 
        Try
            'get the value of the field
            Dim strOrder As String = Me.ddlOrder.SelectedValue
 
            'get the value of the doc amount column
            Dim decDocamount As Decimal
            decDocamount = ddlOrder.EditorControl.Rows(ddlOrder.SelectedIndex).Cells("DocAmount").Value
 
            'use the above values
            Me.txtOrderNumber.Text = strOrder
            Me.txtDocAmount.Text = decDocamount
        Catch ex As Exception
 
        End Try
    End Sub
End Class