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

SelectedIndexChanged doesn't fire for items with the same name

5 Answers 628 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Andrei
Top achievements
Rank 1
Andrei asked on 30 Sep 2016, 10:39 AM

Hello!

I'm having an issue with the RadComboBox control. I have noticed that when there are 2 items that have the same name, let's call them "Combo1", the event SelectedIndexChanged doesn't fire if the user is selecting the second "Combo1" while the current selection is the first "Combo1", or viceversa.

Here's a sample with which I've reproduced the issue:

<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
    
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:scriptmanager runat="server"></asp:scriptmanager>
        
        <telerik:RadComboBox id="ComboBox1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ComboBox1_SelectedIndexChanged">
        <Items>
            <telerik:RadComboBoxItem Text="Combo1" />
            <telerik:RadComboBoxItem Text="Combo2" />
            <telerik:RadComboBoxItem Text="Combo1" />            
        </Items>
        </telerik:RadComboBox>
    </form>
</body>
</html>

 

using System;
using System.Web.UI;

namespace WebApplication2
{
    public partial class WebForm1 : Page
    {
        protected void ComboBox1_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
        {
        }
    }
}

 

Am I doing something wrong or is this a bug? Is there a workaround that I could use in order to get it to work properly?

Best Regards,

Andrei

5 Answers, 1 is accepted

Sort by
0
Anton
Telerik team
answered on 30 Sep 2016, 01:43 PM
Hello Andrei,

In order to have the selection behaving correctly, you need to ensure that the Value property of the RadComboBoxItems is unique. You haven't set any values to the items of the ComboBox which leads to that behavior. More information on this matter is available in this documentation article.

Regards,
Anton
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Andrei
Top achievements
Rank 1
answered on 03 Oct 2016, 07:56 AM

Hello again,
Thank you for the quick reply, Anton!
Then my question is this: What do I do in case I have a TreeView control inside my ComboBox? The TreeView has a Folder->Item hierarchy, where some items will have the same name, but are under different folders. In this situation, I need the "SelectedIndexChanged" event to fire, when a user clicks a node of the tree that has the same name as the one currently selected, but is under a different Folder.( NOTE: the tree is created programmatically) As a final constraint, I cannot use the OnNodeClicked event of the TreeView in order to manually fire the "SelectedIndexChanged".

It is a bit more difficult to provide you with o mock-up of the actual project but I can try and do that if you feel like it would help.

Regards,

Andrei

 

0
Anton
Telerik team
answered on 03 Oct 2016, 01:58 PM
Hello Andrei,

According to the folder of the TreeView you have, you can set an unique value as we discussed. You could also consider using RadDropDownTree. More information on the RadDropDownTree you can find following the link below:

http://docs.telerik.com/devtools/aspnet-ajax/controls/dropdowntree/overview


Regards,
Anton
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Andrei
Top achievements
Rank 1
answered on 17 Oct 2016, 08:00 AM

Hello Anton,

I don't have the option of using the RadDropDownTree because it implies too much refactoring.

I've made sure that all items have unique Values and I'm still seeing the issue. I did find an interesting pattern though. When I load the page that has the RadComboBox with the RadTreeView inside for the first time, if my currently selected value is Combo1 from folder Test1 and I go and click Combo1 from the folder Test2, the SelectedIndexChanged event fires. The "not firing" part only seems to happen after the first selection change. What I'm thinking is... maybe there's a cache somewhere in the RadComboBox control that gets populated after the first selection. Is there something like that? If so, could I clear it?

 

Regards,

Andrei

0
Anton
Telerik team
answered on 20 Oct 2016, 05:39 AM
Hello Andrei,

The RadComboBox has item cashing functionality but it can be used only in the Load-on-demand scenario. However, it is disabled by default and that's why I presume the problem is somewhere else. Have in mind that the SelectedIndexChanged event is fired when different ComboBox items are selected. Having the RadTreeView placed in an item template counts as one item in the ComboBox. So the SelectedIndexChanged won't be fired if you click among the nodes of the TreeView. Indeed it would be fired once when you click anywhere in the TreeView, as it is an item in the ComboBox, but with having no more items, nothing will cause another execution.

Regards,
Anton
Telerik by Progress
Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
Tags
ComboBox
Asked by
Andrei
Top achievements
Rank 1
Answers by
Anton
Telerik team
Andrei
Top achievements
Rank 1
Share this question
or