110,549
社区成员
发帖
与我相关
我的任务
分享
private void Form1_Load(object sender, EventArgs e)
{
var list = new[]
{
new { id = "123", code = "1" },
new { id = "124", code = "2" },
new { id = "125", code = "2" },
new { id = "126", code = "1" },
};
this.dataGridView1.DataSource = list;
var col = new DataGridViewComboBoxColumn();
col.HeaderText = "ComboxCol";
this.dataGridView1.Columns.Add(col);
foreach (DataGridViewRow row in this.dataGridView1.Rows)
{
var comboBox = (DataGridViewComboBoxCell)row.Cells[2];
if (row.Cells[1].Value.ToString() == "1")
comboBox.DataSource = new[] { "a", "b", "c" };
else
comboBox.DataSource = new[] { "1", "2", "3" };
}
}