把datagridview中checkbox中的对勾的颜色弄成红色
Winform上添加一个DataGridView,后台实现代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace RedDatagridViewCheckBox
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(string));
dt.Columns.Add("Sex", typeof(int));
for (int i = 1; i < 10; i++)
{
DataRow dr = dt.NewRow();
dr["ID"] = i.ToString();
dr["Sex"] = 1;
dt.Rows.Add(dr);
}
dataGridView1.DataSource = dt.DefaultView;
DataGridViewCheckBoxColumn dgvc = (DataGridViewCheckBoxColumn)dataGridView1.Columns[1];
dgvc.DefaultCellStyle.ForeColor = Color.Red;
dgvc.FlatStyle = FlatStyle.Popup;
}
}
}
注意:重要的就是红色那几行。