Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>My Domain/Business Model class contains a "Mode" property which is of Type "string". For AUTO/MANUAL/IMPORT modes, the Mode property should contain "A"/"M"/"I" respectively. My domain model is received by my Presentation Model class through the constructor in the Presentation Model.</p> <p>My Presentation Model class contains three boolean variables as "IsAutoMode", "IsManualMode", "IsImportMode". These boolean variables will be used for DataBinding the radio buttons on the Form. The GET/SET for these boolean properties are a little extended to handle updating the corresponding property ("Mode") in the domain model. Note the property GET/SET code in the presentation model class below - </p> <pre><code> public bool IsAutoMode { get { return _domainModel.Mode.ToUpper() == "A"; } set { _domainModel.Mode = (value == true) ? "A" : _domainModel.Mode; } } public bool IsManualMode { get { return _domainModel.Mode.ToUpper() == "M"; } set { _domainModel.Mode = (value == true) ? "M" : _domainModel.Mode; } } public bool IsImportMode { get { return _domainModel.Mode.ToUpper() == "I"; } set { _domainModel.Mode = (value == true) ? "I" : _domainModel.Mode; } } </code></pre> <p>Now, once these boolean properties are setup in your presentation model class, you can easily databind the radio button controls on your Form as below </p> <pre><code>rbtnAutoMode.DataBindings.Add("Checked", _pmodel, "IsAutoMode"); rbtnManualMode.DataBindings.Add("Checked", _pmodel, "IsManualMode"); rbtnImportMode.DataBindings.Add("Checked", _pmodel, "IsImportMode"); </code></pre> <p>and see your radio button databinding fly. The current example stands valid irrespective of what type of property you want to hold in the domain model, be it a "string", "boolean", anything. The key point is to rely on -</p> <pre><code>get { return _domainModel.Mode.ToUpper() == &lt;corresponding domain property val&gt;; } </code></pre> <p>in the property GET rather than returning local field value and to NOT TO set any value in the domain model in case the "value" that comes in the property SET is not TRUE, else let the domain model have its current value</p> <pre><code>set { _domainModel.Mode = (value == true) ? &lt;domain property to set&gt; : _domainModel.Mode; } </code></pre> <p>Another important point is that this type of radiobutton databinding works only when the <code>Binding.DataSourceUpdateMode</code> is set to <code>OnValidation</code> which is the default. If changed to <code>OnPropertyChanged</code> the event firing sequence of the properties, when switching from one button to another button, behaves in a way that prevents evaluation of correct property value for the button to which the control is moving. But the DataSourceUpdateMode is hardly changed in normal applications and thus fortunately this will work for most applications with TWO or MORE radiobuttons.</p> <p>(I was seeing that this question was getting good views but there's no answer posted yet. So I thought I should share what I finally did to solve this.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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