// 禁止编辑
dataGridView1.ReadOnly = true ;
// 设定列数及行数
dataGridView1.ColumnCount = 4;
dataGridView1.RowCount = 5;
dataGridView1.ColumnHeadersVisible = true;
dataGridView1.RowHeadersVisible = true;
//设置列标题
dataGridView1.Columns[0].Name = "Recipe";
dataGridView1.Columns[1].Name = "Category";
//填充单元格
dataGridView1.Rows[1].Cells[0].Value = "1";
dataGridView1.ReadOnly = true ;
// 设定列数及行数
dataGridView1.ColumnCount = 4;
dataGridView1.RowCount = 5;
dataGridView1.ColumnHeadersVisible = true;
dataGridView1.RowHeadersVisible = true;
//设置列标题
dataGridView1.Columns[0].Name = "Recipe";
dataGridView1.Columns[1].Name = "Category";
//填充单元格
dataGridView1.Rows[1].Cells[0].Value = "1";
dataGridView1.Rows[1].Cells[2].Value = "1,2";
//设置单元格字体颜色
dataGridView1.Rows[1].Cells[0].Style.ForeColor= System.Drawing.Color.Red;
//单元格背景色变色
dataGridView1.Rows[1].Cells[0].Style.BackColor = Color.FromName("1"); //灰色dataGridView1.Rows[1].Cells[0].Style.BackColor =
Color.FromName(dataGridView1.Rows[1].Cells[0].Value.ToString());