WinForm DataGridView制作表格
1、 将背景颜色改为白色

this.dataGridView1.BackgroundColor = Color.White;
或

2、 禁止启用添加,启用编辑,启用删除
this.dataGridView1.AllowUserToAddRows = false;
this.dataGridView1.AllowUserToDeleteRows = false;
this.dataGridView1.ReadOnly = true;
或


3、 禁止显示行标题的列
this.dataGridView1.RowHeadersVisible = false;
或

4、 创建列,并绑定字段

设置列宽:

列标题居中,设置编辑,设置字体样式:


文本内容居中,并设置字体:


5、 禁止调整列,行的大小
、
或

6、 设置网格线
//取消视觉样式

//设置网格线样式和颜色




//如果不需要滚动条可以在这里设置

//取消DataGridView边框

//让列宽,行自适应

最后绑定数据源,运行效果如下:


浙公网安备 33010602011771号