RadDropDownList - System.StackOverflowException occurred using 'SelectedValue'

1 Answer 121 Views
DropDownList
Raj
Top achievements
Rank 1
Iron
Iron
Raj asked on 25 May 2023, 11:37 AM | edited on 26 May 2023, 04:29 AM

Hi Team,

We are using RadDropDownList control version (2023.1.314)

We are getting  'System.StackOverflowException' exception while assigning value in the dropdownlist (its keep on recursion).

Could you please help on this?. Please find sample program below.

We are using visual Studio 2022 and Telerik.WinControls.UI.dll(2023.1.314)

Note: Its working fine in 2013.3.1.1127 version.

 private void comboBox1_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
 {
    setOldValue();
 }

 private void setOldValue()
 {
    comboBox1.SelectedValue = 2;
 }

 private void button1_Click(object sender, EventArgs e)
 {
    comboBox1.SelectedValue = 1;
 }

Thanks

Rajkannan

Raj
Top achievements
Rank 1
Iron
Iron
commented on 05 Sep 2023, 04:38 AM

Hi Team,

How to disable the ' OnNotifyPropertyChanged("SelectedValue");' call in RadDropDownList, when assigning the 'SelectedValue' its keep on triggered.

The above workaround unsubscribe/subscribe is working fine. But we are worrying to change/modify in more places.

Could you please help on this at earliest? We are not moving further. since its urgent. 

Note: Its working fine in 2013.3.1.1127 version without modification.

We are using visual Studio 2022 and Telerik.WinControls.UI.dll(2023.1.314)

 Thanks

Rajkannan

1 Answer, 1 is accepted

Sort by
1
Accepted
Dinko | Tech Support Engineer
Telerik team
answered on 26 May 2023, 11:24 AM

Hi Raj,

Probably the reason behind this is that the SelectedValue property is set in the SelectedIndexChanged event (setOldValue() method). What you can do is unsubscribe from the event before setting the SelectedValue property in the event in any way. For example:

private void RadDropDownList1_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
    this.radDropDownList1.SelectedIndexChanged -= RadDropDownList1_SelectedIndexChanged;
    setOldValue();
    this.radDropDownList1.SelectedIndexChanged += RadDropDownList1_SelectedIndexChanged;
}

If that does not help, can you isolate this exception in a standalone project and I will more deeply investigate this.

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.

Raj
Top achievements
Rank 1
Iron
Iron
commented on 29 May 2023, 08:26 AM

Hi Dinko,

Thanks for your reply.

After, unsubscribe and subscribe the event its working fine now.

Thanks

RajKannan

Raj
Top achievements
Rank 1
Iron
Iron
commented on 05 Sep 2023, 04:37 AM

Hi Team,

How to disable the ' OnNotifyPropertyChanged("SelectedValue");' call in RadDropDownList, when assigning the 'SelectedValue' its keep on triggered.

The above workaround unsubscribe/subscribe is working fine. But we are worrying to change/modify in more places.

Could you please help on this at earliest? We are not moving further. since its urgent. 

Note: Its working fine in 2013.3.1.1127 version without modification.

We are using visual Studio 2022 and Telerik.WinControls.UI.dll(2023.1.314)


 

Thanks

Rajkannan

Dinko | Tech Support Engineer
Telerik team
commented on 05 Sep 2023, 01:51 PM

In general, the SelectedValue property is virtual which means that you can create a custom class and override it. This way the default code won't be executed.

public class Custom_DropDownList: RadDropDownList
{
    public override object SelectedValue
    {
        get;
        set;
    }
}

However, this way when setting the SelectedValue property, the control won't be updated as the UI does not know that something is changed. Upon reading again the approach here, we are trying to set the old value of the control in the SelectedIndexChanged event handler. A better solution would be to subscribe to the this.radDropDownList1.DropDownListElement.SelectedIndexChanging event. This event is cancellable. In the event handler, you can get the selected position and cancel the newly selected value before it is even selected. 

private void DropDownListElement_SelectedIndexChanging(object sender, Telerik.WinControls.UI.Data.PositionChangingCancelEventArgs e)
{
    if (e.Position == 5)
    {
        e.Cancel = true;
    }
}

Can you share if this approach is working for you?

 

 

 

Raj
Top achievements
Rank 1
Iron
Iron
commented on 07 Sep 2023, 04:44 AM | edited

Hi Team,

Could you please clarify the below one,

Why this kind of behavior is working fine in 2013.3.1.1127 version and not working in 2023.1.314?

The older version is always working fine without any modification.

Thanks

Rajkannan


Dinko | Tech Support Engineer
Telerik team
commented on 07 Sep 2023, 01:01 PM

I have tested this behavior with the specified version: 2013.3.1.1127 and you are right that the same approach will not lead to an exception, as it should be like in the latest version. In general, it is not recommended to change the selected item in the selection changed event. Changing the selected item in the event handler will trigger the event again. I can agree with you that there is a difference, but this should be the correct behavior. For such purposes, the SelectedIndexChanging event is exposed which is called before the value is changed, where you can execute custom logic and cancel the newly selected item if necessary.

You can share if the SelectedIndexChanging event is working for you. If not, you can share more details regarding your scenario and why it is not working so that I can try to find a suitable solution for you.

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