Telerick version 2024.1.130.48, RadDropDownList controls throwing StackoverflowException when migrating visual studio 2010 to 2022

2 Answers 115 Views
DropDownList
Maheswari
Top achievements
Rank 1
Iron
Iron
Maheswari asked on 05 Feb 2024, 12:31 PM | edited on 05 Feb 2024, 02:28 PM

Hi Dinko and Team,

As I mentioned in my previous forum, The below code is working in VS 2022 with  2013.3.1.1127 where as throwing stackoverflow exception in VS 2022 with Telerk  2024.1.130.48. Out product code structure is like below and we cannot declare and initialize the datatable globally. If we did that the whole application will get impact . Hence could you please restrict the recursive call of Raddropdownlist.Datasource  and Raddropdownlist.SelectedIndex also like Raddropdownlist.SelectedValue. Which I raised in my previous forum

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

public void fillIndustryProcess()

        {
            try
            {
  System.Data.DataTable dt1 = new System.Data.DataTable();
                if (dt1.Columns.Count <= 0)
                {
                    dt1.Columns.Add("Industry", typeof(string));
                    dt1.Columns.Add("ID", typeof(int));
                    dt1.Rows.Add("USA-0", 0);
                    dt1.Rows.Add("USA-1", 1);
                    dt1.Rows.Add("USA-2", 2);
                    dt1.Rows.Add("USA-3", 3);
                    dt1.Rows.Add("USA-4", 4);

                    radDropDownList2.DisplayMember = "Industry";
                    radDropDownList2.ValueMember = "ID";
                }
  radDropDownList2.DataSource = dt1; ;//Still stack overflow exception occurring when bind the radDropDownList
                radDropDownList2.SelectedIndex = 0;
            }
            catch (System.ComponentModel.Win32Exception ex)
            {
                throw ex;
            }
        }

 

Thanks,

Maheswari

                           

2 Answers, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 07 Feb 2024, 11:06 AM

Hello Maheswari,

I appreciate the provided details.

Indeed, I have overlooked that the same exception is raised when setting the DataSource property in selection events. I have already logged this in our Feedback Portal. We are already investigating the item.

I want to elaborate more on the other item that was previously discussed regarding setting the SelectedValue in the SelectedIndexChanged event. We invested time to discuss your complete scenario and we concluded that this is a behavior that is not supported. The standard Microsoft control behaves the same way, and we consider the control behavior that you refer to in the 2013.3.1.1127 version wrong. Setting the SelectedValue property will trigger the SelectedIndexChanged event, and we don't plan to change it in future versions of the controls. The scenario that was fixed here (feedback item) will remove the exception when setting the SelectedValue to an object from the control collection that is already selected. Setting it to a different object will trigger the event again.

I understand that you are unwilling to change the codebase of your application and just to upgrade the version of the Telerik controls. Please note, however, that sometimes when there is such a big distance between the versions, some modifications might be needed. In your scenario, these changes are straight-forward and fairly simple to implement. You have two options.

  1. Use the solution with the flag as discussed in the other item: RadDropDownList: StackOverflowException is thrown when setting SelectedValue to a value on the same index in the SelectedIndexChanged event (telerik.com).
  2. Create a custom control with special handling of the DataSource property. You can replace every RadDropDownList control in your application with a custom one.
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--;
        }
    }
}

Let me know if this will work for you.

Regards,
Dinko | Tech Support Engineer
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.

Maheswari
Top achievements
Rank 1
Iron
Iron
commented on 12 Feb 2024, 07:18 AM | edited

Hi Dinko,

 

I applied the changes whatever you suggested for custom where the stack overflow is resolved and am getting null exceptions when we the set the value for Raddropdownlist irrespective of datasource datatable value then the selectedvalue is getting assigned as null and not retaining the selectedvalue whereas in telerik 2013 it is retaining.

I have attached the code to demonstrate please find that and suggest how to manage the value discrepancy between selectedvalue assigned and datatable value without getting nullexception.

Note: It is occuring in both normal as well as custom raddropdownlist. Please suggest for both irrespective of selectedIndexChangedevent mean if you assign it in button click also selectedvalue is null.

private void radButton1_Click(object sender, EventArgs e)
        {
            radDropDownList1.SelectedValue = 10; // null
            radDropDownList2.SelectedValue = 20; //null
        }    

 

Thanks,

Maheswari

 

 

0
Dinko | Tech Support Engineer
Telerik team
answered on 14 Feb 2024, 02:21 PM
I appreciate the provided project. In general the SelectedValue property points to the property specified to the ValueMember of the control. The SelectedValue is null because there is no such element with the specified ID in the DataSource. The elements inside both collections contain IDs from 0 to 4. The SelectedValue can't be set to a value which does not present in the DataSource. If the SelectedValue in the older version was to an object regardless of that is it not present in the DataSource, then this behavior was wrong. The SelectedValue property will match an item from the DataSource, otherwise it will be set to Null.
Maheswari
Top achievements
Rank 1
Iron
Iron
commented on 14 Feb 2024, 02:31 PM

Hi Dinko,

The same details only I have demonstrated in the POC  project I provided.

So how to achieve the same behavior of telerik 2013 in 2024 version ,- This is what I meant in my previous forum.

Could you please suggest how to retain the value selected currently or previously selected value like telerik 2013  instead of null?

 

Thanks,

Maheswari

Dinko | Tech Support Engineer
Telerik team
commented on 15 Feb 2024, 11:12 AM

You could store the SelectedValue property as a separate variable. Then you can set the SelectedValue to an object and if it goes to Null, use the cached variable value to return the SelectedValue to its previous state. As a note here. Avoid setting the SelectedValue property in the SelectedIndexChanged event handler.

You can store the values of the SelectedValue properties after populating the controls.

object cachedValue = string.Empty;
object cachedValue2 = string.Empty;

private void radButton1_Click(object sender, EventArgs e)
{
    fillIndustryProcess1();

    if (cachedValue != radDropDownList1.SelectedValue && radDropDownList1.SelectedValue != null)
    {
        cachedValue = radDropDownList1.SelectedValue;
    }
    radDropDownList1.SelectedValue = 12;
    if (radDropDownList1.SelectedValue == null)
    {
        radDropDownList1.SelectedValue = cachedValue;
    }

    fillIndustryProcess2();

    if (cachedValue2 != radDropDownList2.SelectedValue && radDropDownList2.SelectedValue != null)
    {
        cachedValue2 = radDropDownList2.SelectedValue;
    }
    radDropDownList2.SelectedValue = 20;
    if (radDropDownList2.SelectedValue == null)
    {
        radDropDownList2.SelectedValue = cachedValue2;
    }
}

 

Tags
DropDownList
Asked by
Maheswari
Top achievements
Rank 1
Iron
Iron
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or