Completed
Last Updated: 22 Nov 2017 08:46 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 13 Nov 2017 08:11
Category:
Type: Bug Report
2
FIX. RadDropDownList - incorrect selection when items with duplicated text but different value exist
This issue is reproducible in RadGridView and RadDropDownList. 

To reproduce: run the attached sample project, type "it" in the editable part and then select the second occurrence of "Item1" from the autocomplete drop-down. You will notice that the first occurrence is selected. However, if you just open the drop down by clicking the arrow, select the second occurrence of "Item1" the correct item is selected. The same behavior is observed in RadGridView in the GridViewComboBoxColumn.

Workaround: 

        private void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
        {
            RadDropDownListEditor editor = e.ActiveEditor as RadDropDownListEditor;
            if (editor != null)
            {
                RadDropDownListEditorElement dropDownEditorElement = editor.EditorElement as RadDropDownListEditorElement;
                dropDownEditorElement.AutoCompleteSuggest = new CustomAutoCompleteSuggestHelper(dropDownEditorElement);
                dropDownEditorElement.AutoCompleteSuggest.SuggestMode = SuggestMode.Contains;
            }
        }

        public class CustomAutoCompleteSuggestHelper : AutoCompleteSuggestHelper
        {
            RadDropDownListElement dropdown;

            public CustomAutoCompleteSuggestHelper(RadDropDownListElement owner) : base(owner)
            {
                dropdown = owner;
            }

            protected override void SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
            {
                int correctIndex = -1;
                if (e.Position > -1)
                {
                    string textFromAutoSuggest = dropdown.ListElement.Items[e.Position].Text;
                    foreach (RadListDataItem item in dropdown.Items)
                    {
                        if (item.Text.Equals(textFromAutoSuggest) && item.Value.Equals(dropdown.ListElement.Items[e.Position].Value))
                        {
                            correctIndex = dropdown.Items.IndexOf(item);
                        }
                    }
                }
                base.SelectedIndexChanged(sender, e);
                if (correctIndex != -1)
                {
                    this.Owner.SelectedIndex = correctIndex;
                }
            } 
        }
0 comments