使用来自此线程的信息,我尝试使用选项设置并动态填充datagridviewcomboboxolumn。我的调试器没有显示错误,但组合框无法渲染。
//setup combobox
List<combo_automation_option> combo = new List<combo_automation_option>();
combo.Add(new combo_automation_option { id = "0", value = "None" });
combo.Add(new combo_automation_option { id = "*.0.5", value = "Once every 5 minutes" });
dgv_col_automation.HeaderText = "Automation";
dgv_col_automation.Name = "dgv_jobs_col_automation";
dgv_col_automation.FlatStyle = FlatStyle.Flat;
dgv_col_automation.DataSource = combo;
dgv_col_automation.ValueMember = "id";
dgv_col_automation.DataPropertyName = "value";
jobs_datagrid.Columns.Add(dgv_col_automation);
当我使用下面的设置来设置我的组合框时,它变得很好:
//setup combobox
dt_col_automation.HeaderText = "Automation";
dt_col_automation.Name = "dgv_jobs_col_automation";
dt_col_automation.Items.AddRange(
"Once every 5 minutes",
"Once every 10 minutes",
"Once every 15 minutes",
"Once every 30 minutes",
"Once every hour",
"Once every 2 hours",
"Once every 3 hours",
"Once every 4 hours",
"Once every 5 hours",
"Once every 6 hours",
"Once every 7 hours",
"Once every 8 hours",
"Once every 9 hours",
"Once every 10 hours",
"Once every 11 hours",
"Once every 12 hours",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"20",
"21",
"22",
"23",
"24"
);
我有一个如下所示的公共结构:
public struct combo_automation_option {
public string id;
public string value;
}
有什么建议吗?
答案 0 :(得分:2)
即使thery是公共的,数据绑定也不适用于类/结构域。
您应该使用属性,例如:
public struct combo_automation_option {
public string id {get; set;}
public string value {get; set;}
}
此外,如果您想在组合框中显示其他内容(例如值)而不是ID,请同时设置DisplayMember
属性。