Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>While I realize this has already been answered, I thought I would provide an option that gives design time binding ability.</p> <p>Make a new Custom RadioButton Object. This is done with the following code.</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; namespace MSLabExample { class RadioButtonBind : RadioButton { private string _selectValue = string.Empty; public string SelectValue { get { return _selectValue; } set { if (value == Text) Checked = true; else Checked = false; _selectValue = value; } } public RadioButtonBind() { this.CheckedChanged += new EventHandler(RadioButtonBind_CheckedChanged); this.TextChanged += new EventHandler(RadioButtonBind_TextChanged); } void RadioButtonBind_TextChanged(object sender, EventArgs e) { if (Checked) _selectValue = Text; } void RadioButtonBind_CheckedChanged(object sender, EventArgs e) { if (Checked) _selectValue = Text; } } } </code></pre> <p>The basic concept of the above control is to use a string value that can be bound and will check itself if the bound string value is equal to the radio button text.</p> <p>By using the radio button text, it allows easy understanding of the proper checked value, and also allows the SelectValue to be updated by simply changing the radio button text. No extra code is needed when modifying the radio button.</p> <p>Now you simply bind the SelectedValue property for all radio buttons in the same group to some string property.</p> <p><strong>Limitations:</strong></p> <ol> <li>Two radio buttons in the same group cannot have the same text (but is this really a limitation?)</li> <li>At design time, the checked values of the radio buttons may not appear accurate (i.e. two radio button in the same group may appear to be checked). This should not occur at runtime however.</li> </ol> <p><strong>Note</strong> when creating a custom control, the project must be built before the custom object is available in the toolbox.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload