TelerikDeveloper.com

TelerikDeveloper.com

sgray128 12/17/2011 11:47:36 AM

Telerik - RadDropDownList

This article covers common coding techniques associated with the Telerik Winforms RadDropDownList.

 



Standard code:

Me.ddlDefaultPurchasingUofM.DisplayMember = "UofM"
Me.ddlDefaultPurchasingUofM.ValueMember = "UofM"
Me.ddlDefaultPurchasingUofM.DataSource = DynData.SPs.FP_IV40202_SEL5(Me.ddlUofMSchedule.SelectedValue, appUser.Db).getTable
Me.ddlDefaultPurchasingUofM.AutoCompleteMode = AutoCompleteMode.SuggestAppend
Me.ddlDefaultPurchasingUofM.DropDownListElement.AutoCompleteSuggest.SuggestMode = SuggestMode.Contains
Me.ddlDefaultPurchasingUofM.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDown
Me.ddlDefaultPurchasingUofM.SelectedIndex = -1
Me.ddlDefaultPurchasingUofM.DropDownListElement.TextBox.TextBoxItem.TextBoxControl.TabStop = True
ddlDefaultPurchasingUofM.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDownList
ddlDefaultPurchasingUofM.DropDownListElement.AutoCompleteAppend.LimitToList = True

Setting the SelectedIndex when populating manually:

Dim i As New RadListDataItem("Cash", 1)
Me.ddlPaymentType.Items.Add(i)
  
i = New RadListDataItem("Check", 2)
Me.ddlPaymentType.Items.Add(i)
  
i = New RadListDataItem("Credit Card", 3)
Me.ddlPaymentType.Items.Add(i)
  
  
For j As Int16 = 1 To 12
     i = New RadListDataItem(j, j)
     Me.ddlCCExpnMonth.Items.Add(i)
Next
  
For j As Int16 = Now.Year To Now.Year + 20
    i = New RadListDataItem(j, j)
    Me.ddlCCExpnYear.Items.Add(i)
Next
 
 
Me.ddlPaymentType.SelectedValue = 1

Setting the SelectedIndex when populating manually:

 

Me.ddlCCExpnMonth.SelectedIndex = Me.ddlCCExpnMonth.DropDownListElement.FindStringExact("1")        
Me.ddlCCExpnYear.SelectedIndex = Me.ddlCCExpnYear.DropDownListElement.FindStringExact("2011")
 
'Note that 'FindStringExact' works on the Text, not the value. to set the selected index using the Value:
Me.ddlEmployee.SelectedValue = strEmployeeID

 

Databinding

'bind a datatable to a stored procedure
Dim oDT As DataTable = DynData.SPs.FP_Trucks_SEL6(App.Database).getTable
 
'bind a telerik dropdownlist to the datasource
Me.ddlTruck.DataSource = oDT
Me.ddlTruck.ValueMember = "Truck"
Me.ddlTruck.DisplayMember = "Truck"
 
'create a new datarow
Dim oRow As DataRow = oDT.NewRow
'add it to the top
oDT.Rows.InsertAt(oRow, 0)
 
'set the ddl to the empty row
Me.ddlTruck.SelectedIndex = 0