CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15

Threaded View

  1. #8
    Join Date
    Jan 2010
    Posts
    1,133

    Re: A couple of radio button questions

    Quote Originally Posted by Arjay View Post
    IMO, programming using Text and/or Tag is a more like an asp scripting hack.
    Well, OK, I agree about the Text property, but only partially about the Tag.
    Sure, Tag can be misused, but I think it's OK to use it for tag-like data (integer index, or string description, or enum), or helper-data, or convenient additional data. I'm not saying that it should be used often, but when used as intended, I don't see why it would be considered a hack.

    I, of course, respect your opinion, and your experience, but I still don't see how the interdependency could be so complex that a class based approach couldn't handle it (with a class to represent a radio button group).

    I combined my idea with what you suggested, and the attached zip is what I came up with. I added some Size-option related behavior to spice it up a bit (one of the labels on the right provides a fictional remark for certain color/size combinations).

    The rough design is shown in the attached image.
    The RadioButtonGroup class tracks the current selection (if any), and provides a way to get the index of the selected radio button. The buttons are sorted by tab index (I chose to use SortedList<> instead of SortedDictionary<>).
    There is an event fired whenever the state of the group is changed, and handlers are provided with all means necessary to do the app logic.

    There is a potential problem with the AutoSelect property of the RadioButton class, since the RadioButtonGroup class relays on the assumption that clients won't change it, but it can be prevented one way or another, I didn't have time to deal with it.

    The dialog has properties which enable the client to check the choices that were made after the dialog is closed.

    This probably needs more work, but it's only to demonstrate the concept.
    And, by the way, the Tag property is not used

    Quote Originally Posted by Arjay View Post
    That sounds pretty good until you need to track several groups of radio buttons that have dependencies and conditions - then the whole thing becomes unwieldy pretty fast.
    I would appreciate if you could show me a scenario where this approach wouldn't work well.

    P.S. Sorry if the code is not documented/commented enough; I suppose that, given this discussion, it's more or less self-explanatory.
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by TheGreatCthulhu; March 4th, 2010 at 12:40 PM. Reason: The P.S., and a thing or 2 to add.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured