日期:2014-05-18  浏览次数:21016 次

如何设置datagridviews中其中几列的对齐方式?
默认全部是左对齐,我想让其中2列数字列设置成右对齐。列表头对齐方式不变!

------解决方案--------------------
C# code

        private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (e.RowIndex > -1)
            {
                if (e.ColumnIndex == 0 || e.ColumnIndex == 1)
                    e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            }
        }