单选按钮检查属性数据绑定 [英] Radio button checked property data binding
问题描述
在我的表格上,有关团体的信息显示为:
1.团体名称:__________(i / p control:textBox)
2.主要是:O否O是(i / p控制:radioButtons)
我想数据绑定上面两个单选按钮的checked属性,与我的对象。
对象如下:
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);
}
绑定文本框工作正常。但是,对于单选按钮,绑定根本不起作用。每当我更改附加到绑定源(bs)的对象时,都不会检查单选按钮。
我对绑定很新。请指导我如何数据绑定一组单选按钮。
我尝试过:
我谷歌搜索单选按钮检查属性数据绑定教程谷歌,但没有任何帮助。我知道这一定是一件容易的事,但我无法弄明白。
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.
推荐答案
CodeProject Article - 将单选按钮绑定到单个属性 [ ^ ]
这篇关于单选按钮检查属性数据绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!