Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 804705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:57:43+00:00 2026-05-14T23:57:43+00:00

I am following the presentation model design pattern suggested by Martin Fowler for my

  • 0

I am following the presentation model design pattern suggested by Martin Fowler for my GUI architecture in a Windows Forms project.

“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….” – Martin Fowler

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.

Supposing I have a Windows Form with three radio buttons to depict some “Mode” options as –

  • Auto
  • Manual
  • Import

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 –

rbtnAutoMode.DataBindings.Add("Text", myBusinessObject, "IsAutoMode");
rbtnManualMode.DataBindings.Add("Text", myBusinessObject, "IsManualMode");
rbtnImportMode.DataBindings.Add("Text", myBusinessObject, "IsImportMode");

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.

There is a good example of binding two radio buttons in Stack Overflow question How do I use databinding with Windows Forms radio buttons?, but I am missing the link while implementing the same with three buttons. I am having very erratic behaviors for the radio buttons.

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.

There is a simple solution to this issue by exposing a method like –

public void SetMode(Modes mode)
{
  this._selectedMode = mode;
}

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T23:57:43+00:00Added an answer on May 14, 2026 at 11:57 pm

    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.

    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 –

        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;
            }
        }
    

    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

    rbtnAutoMode.DataBindings.Add("Checked", _pmodel, "IsAutoMode");
    rbtnManualMode.DataBindings.Add("Checked", _pmodel, "IsManualMode");
    rbtnImportMode.DataBindings.Add("Checked", _pmodel, "IsImportMode");
    

    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 –

    get
    {
      return _domainModel.Mode.ToUpper() == <corresponding domain property val>;
    }
    

    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

    set
    {
      _domainModel.Mode = (value == true) ? <domain property to set> : _domainModel.Mode;
    }
    

    Another important point is that this type of radiobutton databinding works only when the Binding.DataSourceUpdateMode is set to OnValidation which is the default. If changed to OnPropertyChanged 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.

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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone please clarify the following; if a have the following model; presentation-->slide-->video where
I've created the following XAML, approximately (shortened for brevity): <Window ... xmlns:Models=clr-namespace:Project.Presentation.Models;assembly=Project ...> <Window.Resources>
I have the following code that controls the presentation of an interdependent group. The
I've got the following xaml: <Window x:Class=Isolator.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=Isolator Height=394 Width=486 Background=Black WindowStyle=None
I want to apply the following Style to my Polygon : <Style xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:s=clr-namespace:System;assembly=mscorlib
I have read a lot about MVC design pattern, but some of the things
I'm trying to trigger a progress animation when ever the ViewModel/Presentation Model is Busy.
I have the following: class AccountAdmin(models.Model): account = models.ForeignKey(Account) is_master = models.BooleanField() name =
I have the following simple custom control that I have defined for a Windows
I was reading the following presentation: http://wingolog.org/pub/qc-2012-js-slides.pdf which talks about (4,10,19) inline ASM generation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.