Pragmatically Call the SelectedIndex Change event for Dropdownlist

2 posts, 0 answers
  1. Denis Cilliers
    Denis Cilliers avatar
    62 posts
    Member since:
    Jan 2004

    Posted 01 Nov 2012 Link to this post

    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
  2. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 02 Nov 2012 Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top