Skip to main content

DatagridView Cell Alignment

  • February 15, 2013
  • 0 replies
  • 0 views

Problem:

How can you dynamically change the alignment of Text in a cell of a DataGridView in .Net ?

Resolution:

There is an enumeration "DataGridViewContentAlignment" that allows you to set the alignment in a cell. You can use this using code such as:-

           set DataGridView1::"Columns"::"Item"(0)::"DefaultCellStyle"::"Alignment"

               to cDataGridViewContentAlignment::"TopCenter"

           set DataGridView1::"Columns"::"Item"(1)::"DefaultCellStyle"::"Alignment"

               to cDataGridViewContentAlignment::"TopCenter"

A full demo is attached to this article.

Attachments:

DataGridView.zip

Old KB# 1521