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

SelectedIndexChanged not firing from suggested dropdownlist

4 Answers 243 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Karl
Top achievements
Rank 1
Karl asked on 26 Sep 2012, 12:25 AM
Hi,

I have a commandbardropdownlist control with AutoCompleteMode set to SuggestAppend. When data is entered, typed into the textbox, the suggested dropdown list works correct. Selecting an item of this suggested list does not seem to fire the SeletedIndexChanged event. Could you check out this issue or what could I have set incorrect?

Thanks,

Karl

4 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 28 Sep 2012, 09:09 AM
Hi Karl,

Thank you for writing.

I have tested the described behavior and on my end the event si fired correctly in all three cases - typing the item name and pressing enter, selecting it with mouse from the autocomplete popup and moving through the items in the autocomplete popup with arrow keys.

Attached you can find a sample video.

Could you please provide me with a sample where the issue can be reproduced, so we can investigate it and provide you with adequate support.

I am looking forward to your reply.
 
Greetings,
Stefan
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Karl
Top achievements
Rank 1
answered on 29 Sep 2012, 10:54 AM
Dear Stephan,
Thank you for the movie - and I can see it works at your end. 

I'm going to send you some relevant code and lets see if we can track this down.
//
// commandBarDropDownList1
//
this.commandBarDropDownList1.AccessibleDescription = "commandBarDropDownList1";
this.commandBarDropDownList1.AccessibleName = "commandBarDropDownList1";
this.commandBarDropDownList1.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.commandBarDropDownList1.DefaultItemsCountInDropDown = 35;
this.commandBarDropDownList1.DisplayName = "commandBarDropDownList1";
this.commandBarDropDownList1.DropDownAnimationEnabled = true;
this.commandBarDropDownList1.MaxDropDownItems = 0;
this.commandBarDropDownList1.MinSize = new System.Drawing.Size(156, 22);
this.commandBarDropDownList1.Name = "commandBarDropDownList1";
this.commandBarDropDownList1.Text = "";
this.commandBarDropDownList1.Visibility = Telerik.WinControls.ElementVisibility.Visible;
this.commandBarDropDownList1.SelectedIndexChanged += new Telerik.WinControls.UI.Data.PositionChangedEventHandler(this.commandBarDropDownList1_SelectedIndexChanged);
this.commandBarDropDownList1.ItemDataBound += new Telerik.WinControls.UI.ListItemDataBoundEventHandler(this.commandBarDropDownList1_ItemDataBound);

this is where i fill it

private void RadForm6ListView_Load(object sender, EventArgs e)
{
    // this.commandBarDropDownList1.ItemDataBound -= new Telerik.WinControls.UI.ListItemDataBoundEventHandler(this.commandBarDropDownList1_ItemDataBound);
    this.Text = "Liste";
    this.FillTableAndConnect2ListView();
    this.radListView1.AllowEdit = false;
    this.radListView1.AllowRemove = false;
    this.radListView1.ViewType = ListViewType.IconsView;
    string thisSQL = " SELECT Count(T_Tag.GlossarID) AS Anzahl, T_Glossar.DE as Begriff, T_Glossar.GlossarID as ID ";
    thisSQL += " FROM T_Glossar LEFT JOIN T_Tag ON T_Glossar.GlossarID = T_Tag.GlossarID ";
    thisSQL += " GROUP BY T_Glossar.DE, T_Glossar.GlossarID ";
    thisSQL += " HAVING (((Count(T_Tag.GlossarID))>0)) ";
    thisSQL += " ORDER BY T_Glossar.DE;";
    FillDropDown(thisSQL, this.commandBarDropDownList1);

and here if it is selected
private void commandBarDropDownList1_ItemDataBound(object sender, ListItemDataBoundEventArgs args)
{
    //  DataRow newrow = (DataRow)args.NewItem.DataBoundItem;
    DataRowView view = (DataRowView)args.NewItem.DataBoundItem;
    args.NewItem.Text = view["Begriff"].ToString().Trim() + "  " + view["Anzahl"];
}
 
private void commandBarDropDownList1_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
    if (commandBarDropDownList1.SelectedValue == null) return;
    this.radListView1.FilterDescriptors.Clear();
    string smyGlossarID = commandBarDropDownList1.SelectedValue.ToString();
    if (smyGlossarID == "System.Data.DataRowView") return;
The SelectedIndexChanged is never reached if I type text into the textbox.

I hope this helps.

Karl
0
Accepted
Stefan
Telerik team
answered on 01 Oct 2012, 01:49 PM
Hi Karl,

The observed behavior is caused by the fact that you are changing the item text in the ItemDataBound event. When you attempt to change the selected item it searches for the item text and since you have changed it, the control is not able to find the corresponding item to select it. This is the default behavior and it cannot be changed. 

What I can offer is to change the item text in the VisualItemFormatting event instead of the ItemDataBound event, however, this will only change the item appearace in the main drop down:
void commandBarDropDownList1_VisualItemFormatting(object sender, Telerik.WinControls.UI.VisualItemFormattingEventArgs args)
{
    DataRowView view = (DataRowView)args.VisualItem.Data.DataBoundItem;
    args.VisualItem.Text = view["Name"].ToString().Trim() + "  " + view["Id"];
}

Alternatively, you can use unbound mode and populate the control with items with whatever text you want.

I hope this helps.
 
Kind regards,
Stefan
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Karl
Top achievements
Rank 1
answered on 01 Oct 2012, 03:36 PM
Thank you Stephan!
It works perfectly!
Karl
Tags
DropDownList
Asked by
Karl
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Karl
Top achievements
Rank 1
Share this question
or