Control selection event alternatives
-
In controls that allow selection of a thing, I've seen two common ways to inform the user that the currently selected thing has changed and what the new selected thing is. In the first method, the event notification arguments contain no extra information about the selected thing but the control has a property for accessing it.
private void someControl_SelectedThingChanged(object sender, EventArgs e)
{
SomeControl someControl = sender as SomeControl;
SomeThing selectedThing = someControl.SelectedThing;
...
}In the second method, the new selected thing is a property of the event notification arguments.
private void someControl_SelectedThingChanged(object sender, SelectedThingChangedEventArgs e)
{
SomeThing selectedThing = e.SelectedThing;
...
}One advantage I can see of one method over the other is that the first method is useful if the SomeControl.SelectedThing property is read/write and can be set via code and not just input events. If the SomeControl.SelectedThing property is read-only, then it doesn't really need to exist and the value can be passed in the event arguments as per the second method. Agree? Disagree? Discuss ...