Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > center the text in each cell of dataGridView
 

center the text in each cell of dataGridView

What property do I need to set to center justify the text in each of the cell of my dataGridView? It is currently left justify.
DotNetUser  Thursday, July 12, 2007 11:14 PM

Code Snippet

DataGridView1.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter

DataGridView1.DataSource = ds.Tables("Products")

Ken Tucker  Friday, July 13, 2007 9:50 AM

Code Snippet

DataGridView1.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter

DataGridView1.DataSource = ds.Tables("Products")

Ken Tucker  Friday, July 13, 2007 9:50 AM

To center the column header:

newCol->HeaderCell->Style->Alignment= DataGridViewContentAlignment::MiddleCenter;

DotNetUser  Friday, July 13, 2007 4:20 PM

You can use google to search for other answers

Custom Search

More Threads

• DataGridView Flicker
• How to show data in lable with Dataset?
• BindingSources, nested relations, look-up table, help.
• VS2005 DataGridView
• ERROR system.argumentexception: datagridviewcomboboxcell value is not valid
• Combine datatable common rows into single row with comma seperated cell
• Custom Drag/Drop Reordering of Rows/Columns in DataGridView
• removing a row from a datatable by clicking the row in the datagridview it belongs to
• How to convert JoinView to DataTable
• How to programmatically change a bound combobox