如果某列的值为0时,combobox的值为1,2,3
如果某列的值为1时,combobox的值为4,5,6

解决方案 »

  1.   

    绑定之后,判断设定就OK。 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" };     
         }
     }