C#语言DataGridView表头、列、行、单元格居中问题

您所在的位置:网站首页 excel表头居中 C#语言DataGridView表头、列、行、单元格居中问题

C#语言DataGridView表头、列、行、单元格居中问题

2024-06-25 04:47| 来源: 网络整理| 查看: 265

表头一般指列标题——列头,这里也包括行头,例如已经定义了DataGridView的一个对象dgvTest 1、行头居中:设置dgvTest的RowHeaderDefaultStyle属性的Alignment的值为MiddleCenter; 2、列头居中:设置dgvTest的ColumnHeaderDefaultStyle属性的Alignment值为MiddleCenter; 3、某一列居中:dgvTest的属性【Columns】->选中要居中的列,然找找到【DefaultCellStyle】->设置Alignment的值为MiddleCenter; 4、某一行居中:dgvTest.Rows[i].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; 5、某一个单元格居中:首先顶一个单元格样式对象,然后设置该对象的值,最后把该单元格的Style属性设置为该对象。例如:     DataGridViewCellStyle dgvcStyle = new DataGridViewCellStyle();     dgvcStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;     dgvTest.Rows[i].Cells[j].Style = dgvcStyle;



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3