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

ComboBoxColumn DropDownList 1st Value Not Selectable

2 Answers 100 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Justin
Top achievements
Rank 1
Justin asked on 18 Feb 2012, 11:53 PM
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 Answers, 1 is accepted

Sort by
0
Boryana
Telerik team
answered on 21 Feb 2012, 04:46 PM
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 >>
0
Justin
Top achievements
Rank 1
answered on 26 Feb 2012, 03:15 AM
Thanks Boryana that did the job.
Tags
GridView
Asked by
Justin
Top achievements
Rank 1
Answers by
Boryana
Telerik team
Justin
Top achievements
Rank 1
Share this question
or