ComboBoxColumn DropDownList 1st Value Not Selectable

3 posts, 0 answers
  1. Justin
    Justin avatar
    8 posts
    Member since:
    Aug 2011

    Posted 18 Feb 2012 Link to this post

    Hi,

    I am having trouble with the first value displayed in a dropdownlist. The column is bound to a datasource that contains all possible values in the forms load event. Under the cell editor initialized event I change the drop down list editor element's datasource to only show relevant values based on another columns value. This is all working fine with correct values being populated in the list. However if I select the first value in the drop down list it does not display. All the other values work as expected.

     

    Load event:
    Dim ListDisplayColumn As GridViewComboBoxColumn = dgvReportingIndicators.Columns("ListSwitchDisplay")
                ListDisplayColumn.DataSource = Me.TrafficLightIndicatorsTableAdapter.GetData
                ListDisplayColumn.DisplayMember = "DisplayName"
                ListDisplayColumn.FieldName = "ListSwitch"
                ListDisplayColumn.ValueMember = "ID"

    CellEditorInitialized event:
    If e.Column.Name = "ListSwitchDisplay" Then
                    Dim dropDownEditor = TryCast(dgvReportingIndicators.ActiveEditor, RadDropDownListEditor)
                    Dim element = TryCast(dropDownEditor.EditorElement, RadDropDownListEditorElement)
                    Select Case e.Row.Cells("IndicatorTypeDisplay").Value
                        Case "Count"
                            element.DataSource = Me.TrafficLightIndicatorsTableAdapter.GetNotApplicable
                        Case "Traffic Light"
                            element.DataSource = Me.TrafficLightIndicatorsTableAdapter.GetTL
                    End Select
                    element.ShowPopup()
                End If
  2. Boryana
    Admin
    Boryana avatar
    330 posts

    Posted 21 Feb 2012 Link to this post

    Hi Justin,

    Thank you writing.

    When you reset the RadDropDownListEditor datasource in the CellEditorInitilized handler, the editor automatically selects the first item. This is the standard binding behavior of all controls in our suite. To overcome it, you can set the SelectedIndex to -1 after you reset the datasource. Here is how the EventHandler should look like:
    If e.Column.Name = "ListSwitchDisplay" Then
        Dim dropDownEditor = TryCast(dgvReportingIndicators.ActiveEditor, RadDropDownListEditor)
        Dim element = TryCast(dropDownEditor.EditorElement, RadDropDownListEditorElement)
        Select Case e.Row.Cells("IndicatorTypeDisplay").Value
            Case "Count"
                element.DataSource = Me.TrafficLightIndicatorsTableAdapter.GetNotApplicable
            Case "Traffic Light"
                element.DataSource = Me.TrafficLightIndicatorsTableAdapter.GetTL
        End Select
       'Add the following line
        element.SelectedIndex = -1
        element.ShowPopup()
    End If

    I hope you find my answer useful. Let me know if you encounter further issues. 

    Kind regards,
    Boryana
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. Justin
    Justin avatar
    8 posts
    Member since:
    Aug 2011

    Posted 25 Feb 2012 Link to this post

    Thanks Boryana that did the job.
Back to Top