Note that there are some explanatory texts on larger screens.

plurals
  1. POWindows Forms radiobutton data binding
    primarykey
    data
    text
    <p>I am following the <a href="http://martinfowler.com/eaaDev/PresentationModel.html" rel="nofollow noreferrer">presentation model</a> design pattern suggested by <a href="http://en.wikipedia.org/wiki/Martin_Fowler" rel="nofollow noreferrer">Martin Fowler</a> for my GUI architecture in a Windows Forms project.</p> <p>"<em>The essence of a Presentation Model is of a fully self-contained class that represents all the data and behavior of the UI window, but without any of the controls used to render that UI on the screen. A view then simply projects the state of the presentation model onto the glass...."</em> - Martin Fowler</p> <p>I am finding the concept very fluid and easy to understand except this one issue of data binding RadioButtons to properties on the Data/Domain object.</p> <p>Supposing I have a Windows Form with three radio buttons to depict some "Mode" options as -</p> <ul> <li>Auto</li> <li>Manual</li> <li>Import</li> </ul> <p>How can I use boolean properties on Data/Domain Objects to DataBind to these buttons? I have tried many ways but to no avail. For example I would like to code like -</p> <pre><code>rbtnAutoMode.DataBindings.Add("Text", myBusinessObject, "IsAutoMode"); rbtnManualMode.DataBindings.Add("Text", myBusinessObject, "IsManualMode"); rbtnImportMode.DataBindings.Add("Text", myBusinessObject, "IsImportMode"); </code></pre> <p>There should be a fourth property like "SelectedMode" on the data/domain object which at the end should depict a single value like "SelectedMode = Auto". I am trying to update this property when any of the "IsAutoMode", "IsManualMode" or "IsImportMode" is changed, e.g. through the property setters. I have INotifyPropertyChanged implemented on my data/domain object so, updating any data/domain object property automatically updates my UI controls, that's not an issue.</p> <p>There is a good example of binding two radio buttons in Stack&nbsp;Overflow question <em><a href="https://stackoverflow.com/questions/344964/how-do-i-use-databinding-with-windows-forms-radio-buttons">How do I use databinding with Windows Forms radio buttons?</a></em>, but I am missing the link while implementing the same with three buttons. I am having very erratic behaviors for the radio buttons.</p> <p>I hope I was able to explain it reasonably. I am actually in a hurry and could not put a detailed code on post, but any help in this regard is appreciated.</p> <p>There is a simple solution to this issue by exposing a method like -</p> <pre><code>public void SetMode(Modes mode) { this._selectedMode = mode; } </code></pre> <p>which could be called from the "CheckedChanged" event of the radio buttons from the UI and would perfectly set the "SelectedMode" on the business object, but I need to stretch the limits to verify whether this can be done by DataBinding.</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.
 

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