C# 基于datatable在每行中使用不同的数据绑定radiogroup
我添加了两列gridcontrol,第1列表示string和bind from datatable,另一列表示radiogroupitem,但我想根据问题在每行中添加不同的radiobutton值,就像第一行add中一样 (好-不好)和下一行添加(此处-不在此)和最后一行添加(尚未-是-今晚) 使用事件为单个单元格分配不同的编辑器。您可以在字典中存储问题和RepositoryItemRadioGroup:C# 基于datatable在每行中使用不同的数据绑定radiogroup,c#,winforms,devexpress,C#,Winforms,Devexpress,我添加了两列gridcontrol,第1列表示string和bind from datatable,另一列表示radiogroupitem,但我想根据问题在每行中添加不同的radiobutton值,就像第一行add中一样 (好-不好)和下一行添加(此处-不在此)和最后一行添加(尚未-是-今晚) 使用事件为单个单元格分配不同的编辑器。您可以在字典中存储问题和RepositoryItemRadioGroup: Dictionary<string, RepositoryItemRadioGrou
Dictionary<string, RepositoryItemRadioGroup> repositories = new Dictionary<string, RepositoryItemRadioGroup>();
RepositoryItemRadioGroup group1 = new RepositoryItemRadioGroup();
group1.Items.Add(new DevExpress.XtraEditors.Controls.RadioGroupItem("Fine", "Fine"));
group1.Items.Add(new DevExpress.XtraEditors.Controls.RadioGroupItem("Bad", "Bad"));
repositories.Add("How are you?", group1);
RepositoryItemRadioGroup group2 = new RepositoryItemRadioGroup();
group2.Items.Add(new DevExpress.XtraEditors.Controls.RadioGroupItem("Here", "Here"));
group2.Items.Add(new DevExpress.XtraEditors.Controls.RadioGroupItem("There", "There"));
repositories.Add("Where are you?", group2);
另见:
Dictionary<string, RepositoryItemRadioGroup> repositories = new Dictionary<string, RepositoryItemRadioGroup>();
RepositoryItemRadioGroup group1 = new RepositoryItemRadioGroup();
group1.Items.Add(new DevExpress.XtraEditors.Controls.RadioGroupItem("Fine", "Fine"));
group1.Items.Add(new DevExpress.XtraEditors.Controls.RadioGroupItem("Bad", "Bad"));
repositories.Add("How are you?", group1);
RepositoryItemRadioGroup group2 = new RepositoryItemRadioGroup();
group2.Items.Add(new DevExpress.XtraEditors.Controls.RadioGroupItem("Here", "Here"));
group2.Items.Add(new DevExpress.XtraEditors.Controls.RadioGroupItem("There", "There"));
repositories.Add("Where are you?", group2);
void GridView1_CustomRowCellEdit(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e) {
GridView view = sender as GridView;
if (e.Column.FieldName == "Answer" && view.IsValidRowHandle(e.RowHandle)) {
string question = (string)view.GetRowCellValue(e.RowHandle, "Question");
RepositoryItemRadioGroup item;
if(repositories.TryGetValue(question, out item))
e.RepositoryItem = item;
}
}