1 Answer, 1 is accepted
Hi, Mark,
Setting the RadDropDownList.ReadOnly property internally sets the DropDownListElement.ListElement.ReadOnly property. Indeed, there is no event being triggered when the property is modified.
However, I have prepared a sample code snippet demonstrating how to create a custom ReadOnlyChanged event and use it to track the changes in the event:
public class CustomDropDown : RadDropDownList
{
public event EventHandler<ReadOnlyEventArgs> ReadOnlyChanged;
public override string ThemeClassName
{
get
{
return typeof(RadDropDownList).FullName;
}
}
protected virtual void OnReadOnlyChanged(bool _readOnly)
{
if (ReadOnlyChanged != null)
ReadOnlyChanged(this, new ReadOnlyEventArgs(_readOnly));
}
public void SetReadOnly(bool isReadOnly)
{
this.ReadOnly = isReadOnly;
ReadOnlyChanged(this, new ReadOnlyEventArgs(isReadOnly));
}
}
public class ReadOnlyEventArgs : EventArgs
{
public ReadOnlyEventArgs(bool isReadOnly)
{
ReadOnly = isReadOnly;
}
public bool ReadOnly { get; private set; }
}
((CustomDropDown)this.radDropDownList1).ReadOnlyChanged += DropDown_ReadOnlyChanged;
private void RadDropDownList1_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
Console.WriteLine( e.PropertyName);
}
I hope this information helps. If you need any further assistance please don't hesitate to contact me.
Regards,
Dess | Tech Support Engineer, Principal
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.
Thank you, This is exactly what I was looking for. I will try this out.
Thank You.
public class CustomDropDown : RadDropDownList
{
public event EventHandler<ReadOnlyEventArgs> ReadOnlyChanged;
protected virtual void OnReadOnlyChanged(bool _readOnly)
{
ReadOnlyChanged?.Invoke(this, new ReadOnlyEventArgs(_readOnly));
}
public override string ThemeClassName
{
get
{
return typeof(RadDropDownList).FullName;
}
}
public override bool ReadOnly
{
get => base.ReadOnly;
set
{
base.ReadOnly = value;
OnReadOnlyChanged(value);
}
}
}
public class ReadOnlyEventArgs : EventArgs
{
public ReadOnlyEventArgs(bool isReadOnly)
{
ReadOnly = isReadOnly;
}
public bool ReadOnly { get; private set; }
}
Hi, Mark,
The purpose of the OnReadOnlyChanged method is to raise the event handler if there is any subscriptions to the event. Additional information about the demonstrated approach with creating a custom event is demonstarted here: https://learn.microsoft.com/en-us/dotnet/desktop/winforms/controls/defining-an-event-in-windows-forms-controls?view=netframeworkdesktop-4.8
As to the alternative solution in your last post, I can confirm that it is OK and you can use it in your scenario. Should you have further questions please let me know.