DataGridView 经常用到,但是很多东西都不熟悉,以至于总去上网查,这次我整理一下,全部都记下来,再用就方便了。

1、禁止用户新建行,就是去掉最后那个行标题上带星号的那个行

dataGridView1.AllowUserToAddRows = false;

2、去掉左侧的行标题

dataGridView1.RowHeadersVisible = false;

3、禁止用户调整列和行

dataGridView1.AllowUserToResizeColumns = false;
dataGridView1.AllowUserToResizeRows = false; 

4、禁止用户编辑单元格

dataGridView1.ReadOnly = true;

5、直接选中一整行

dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

 6、将单元格内的文本居中显示

dataGridView1.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

7、将列头内的文字居中显示

dataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

 8、修改当前选中行的背景色和前景色

dataGridView1.DefaultCellStyle.SelectionBackColor = Color.FromArgb(139, 185, 201);
dataGridView1.DefaultCellStyle.SelectionForeColor = Color.Black;

9、设置用户是否可以选中多行、多列、多单元格

dataGridView1.MultiSelect = true;

 

相关文章:

  • 2021-10-03
  • 2022-02-08
  • 2021-07-25
  • 2022-12-23
  • 2022-12-23
  • 2022-01-24
  • 2021-05-20
  • 2022-12-23
猜你喜欢
  • 2021-12-02
  • 2021-06-18
  • 2021-06-01
  • 2021-05-10
  • 2021-11-11
  • 2021-10-30
  • 2022-12-23
相关资源
相似解决方案