Declined
Last Updated: 07 Feb 2024 13:05 by ADMIN
Maheswari
Created on: 06 Feb 2024 14:56
Category: UI for WinForms
Type: Bug Report
0
RadDropDownList: StackOverflowException is thrown when setting up the radDropDownList1.SelectedIndex in radDropDownList1_SelectedIndexChanged event

Hi Dinko and Team,

As I mentioned in the previous forum, We need fix for Raddropdownlist.SelectedIndex.

When we set SelectedIndex=5 or some value in selectedIndexchangedEvent then the recursive call is happening for SelectedIndex. So we need to restrict the recursive call for both Raddropdownlist.DataSource as well as Raddropdownlist.SelectedIdex.

  private void radDropDownList1_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
        {
           fillIndustryProcess1(); // radDropDownList1.DataSource = dt; when we set Datasource the recursive call is occurring
            radDropDownList1.SelectedIdex = 5; // radDropDownList1.SelectedIdex= 5; when we set Datasource the recursive call is occurring

}

public void fillIndustryProcess1()
        {
            try
            {
                System.Data.DataTable dt = new System.Data.DataTable();
                if (dt.Columns.Count > 0)
                    {
                        dt.Columns.Add("Industry", typeof(string));
                        dt.Columns.Add("ID", typeof(int));
                        dt.Rows.Add("BGL-0", 0);
                        dt.Rows.Add("BGL-1", 1);
                        dt.Rows.Add("BGL-2", 2);
                        dt.Rows.Add("BGL-3", 3);
                        dt.Rows.Add("BGL-4", 4);
                        radDropDownList1.DisplayMember = "Industry";
                        radDropDownList1.ValueMember = "ID";
                    }
                radDropDownList1.DataSource = dt;// Recursive call occurs
                radDropDownList1.SelectedIndex = 0;/ Recursive call occurs
            }
            catch (System.ComponentModel.Win32Exception ex)
            {
                throw ex;
            }
        }

Old Forums in which , Telerik team fixed the RadDropDownList .SelectedValue.

Telerick version 2023.1.314 RadDropDownList controls throwing StackoverflowException when migrating visual studio 2010 to 2022 in UI for WinForms | Telerik Forums 

Previous forums in which , Telerik team yet to fix for RadDropDownList.Datasource.

Telerick version 2024.1.130.48, RadDropDownList controls throwing StackoverflowException when migrating visual studio 2010 to 2022 in UI for WinForms | Telerik Forums

Thanks,

Maheswari

1 comment
ADMIN
Todor
Posted on: 07 Feb 2024 13:05

Hello Maheswari,

I have read your previous communication with our support and I understand that you are upgrading from version 2013 to the latest. Over this 10+ year period, there have been numerous behavior improvements, bug fixes, and API improvements to the RadDropDownList control. Note that such an upgrade may cause some difficulties and you may need to change your code, but it is worth the effort.

When you set the SelectedIndex in the SelectedIndexChanged event, everything works as expected - the SelectedIndex is changed accordingly.

The code you have attached illustrates an unsupported scenario where the DataSource is set (rebind the RadDropDownList control) in the SelectedIndexChanged event and then set the SelectedIndex to 5 in this particular case. This causes recursive calls to the event handler and results in a StackOverflowException.

We discussed this very specific scenario with the development team and concluded the following:

  1. If we change the code of RadDropDownList to support this scenario, it would lead to breaking changes in current behavior, which would break the correct operation of already existing applications.
  2. It is correct for SelectedIndexChanged to be fired when both SelectedIndex and SelectedValue properties are changed. Our customers also expect events to be triggered in the existing way. So when you explicitly change SelectedIndex or SelectedValue in this event to a different value each time, it's up to the developer to protect against recursive calls to SelectedIndexChanged event.
  3. We tested the same scenario with MS ComboBox and it also throws the same exception with the same setup.

For these reasons, we decided that this scenario is not valid for the RadDropDownList control and it should not support it out of the box. Therefore we have declined the bug report. 

However, you can easily achieve the desired scenario by raising a flag or counter. We have prepared a custom implementation of RadDropDownList for your custom scenario:

public class MyDropDownList : RadDropDownList
{
    private int suspendEventCount = 0;
 
    public MyDropDownList() { }
 
    public override string ThemeClassName
    {
        get { return typeof(RadDropDownList).FullName; }
        set { base.ThemeClassName = value; }
    }
 
    protected override void OnSelectedIndexChanged(object sender, int newIndex)
    {
        if (this.suspendEventCount > 0)
        {
            return;
        }
 
        base.OnSelectedIndexChanged(sender, newIndex);
    }
 
    public new object DataSource
    {
        get { return base.DataSource; }
        set
        {
            this.suspendEventCount++;
            base.DataSource = value;
            this.suspendEventCount--;
        }
    }
 
    public override object SelectedValue
    {
        get { return base.SelectedValue; }
        set
        {
            this.suspendEventCount++;
            base.SelectedValue = value;
            this.suspendEventCount--;
        }
    }
}

Regards,


Todor
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.