This is a migrated thread and some comments may be shown as answers.

Pragmatically Call the SelectedIndex Change event for Dropdownlist

1 Answer 82 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Denis Cilliers
Top achievements
Rank 1
Denis Cilliers asked on 01 Nov 2012, 11:48 AM
Hi I need to call the SelectedIndex event after loading the form.
The reason for this is that the dropdownlist determines if other controls are displayed on the form

here is a example of the idea
Partial Class Example
     Public Function LoadData() As Boolean
      
       Me.DropDownList1.DataSource = Types.ConfirmationType
 
        If Not CustomerName Is Nothing Then
 
            ' Where the DropDownlist ID is DropDownList1
            Me.DropDownList1.SelectedText = "Driver"
             
            ' Calls the method directly passing the appropriate sender
            Me.DropDownList1_SelectedIndexChanged(Me.DropDownList1, Nothing)
        End If
     End Function
 
    Protected Sub DropDownList1_SelectedIndexChanged(sender As System.Object, e As Telerik.WinControls.UI.Data.PositionChangedEventArgs) Handles DropDownList1.SelectedIndexChanged
          
        Dim options As String = Me.DropDownList1.SelectedText
 
        Select Case options
            Case "Driver"
                'Display the Driver mobile fields
                Me.lblDriverMobile.Visible = True
                Me.txtDriverMobile.Visible = True
                Me.ddlDriverMobileCode.Visible = True
                Me.pbDriverMobile.Visible = True
            Case Else
                'Hide the Driver mobile fields
                Me.lblDriverMobile.Visible = False
                Me.txtDriverMobile.Visible = False
                Me.ddlDriverMobileCode.Visible = False
                Me.pbDriverMobile.Visible = False
 
        End Select
     End Sub
End Class

The issue is that the call does not happen and the line 

Me.DropDownList1_SelectedIndexChanged(Me.DropDownList1, Nothing)

Does not seem to work ?
What I get in the options value is a empty string ?

Any ideas

1 Answer, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 02 Nov 2012, 07:58 AM
Hello,

I am not sure that I fully understand your scenario and I would like to clarify that the SelectedText property represents the selected text in RadDropDownList's TextBox, e.g. the selected text into text editor part of RadDropDownList. You should change the selection in this way:
Me.DropDownList1.SelectedIndex = Me.DropDownList1.FindString("Driver")

Let me know if you need further assistance with this.
Greetings,
Peter
the Telerik team
Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.
Tags
DropDownList
Asked by
Denis Cilliers
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or