Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. Control selection event alternatives

Control selection event alternatives

Scheduled Pinned Locked Moved Windows Forms
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Adrian Cole
    wrote on last edited by
    #1

    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 ...

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups