Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
On my form information about a group is displayed as:

1. Group Name:__________ (i/p control: textBox)
2. Is Primary: O No O Yes (i/p control: radioButtons)

I want to data bind the checked property of the two radio buttons above, with my object.
The object is as:
public class DTOItemGroup
    {
        public short id { get; set; }
        public string name { get; set; }
        public Nullable<short> idParent { get; set; }
    }


Back in the code, I tried binding it as:
BindingSource bs;
void InitializeThis(StockTools stockTools)
        {
            bs = new BindingSource();
            bs.DataSource = typeof(DTOItemGroup);
            form_StockTools.tb_GroupName.DataBindings.Add("Text", bs, "name");
            form_StockTools.rb_IsPrimaryNo.DataBindings.Add("Checked", bs, "idParent", true, DataSourceUpdateMode.OnPropertyChanged, false);
            form_StockTools.rb_IsPrimaryYes.DataBindings.Add("Checked", bs, "idParent", true, DataSourceUpdateMode.OnPropertyChanged, true);
        }


Binding for the textbox is working fine. But, for radio buttons, binding is not working at all. Whenever I change the object attached to binding source (bs), the radio buttons doesn't get checked.

I am very new to binding. Please guide me on how to data bind a group of radio buttons.

What I have tried:

I googled for radio button checked property data binding tutorial over google but had no help. I know this must be an easy task, but I can't really figure out it.
Posted
Updated 15-Mar-17 2:05am

1 solution

 
Share this answer
 
Comments
Member 11040029 15-Mar-17 10:40am    
Thats a XAML solution John...I mentioned c#...if you find any good link for c#, please post...thnx anyway


#realJSOP 16-Mar-17 9:23am    
If you have the xaml way to do it, it's a reasonably simple matter to convert that to c# because XAML is just a markup for the classes that are used.

Voting my answer a one does not compel me to help you further.
Member 11040029 16-Mar-17 9:55am    
ye there is xaml, but the c# equivalent is not working...I voted your answer to 1 because your answer doesn't answer my question John..there is nothing to be compelled or not...if you provide me some better answer, I will surely update the stars :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900