More Group Sites
School Rankings
Jobless Net
Better Home
Enviro++


Help | Subscribe/Unsubscribe | Rules | Other Group Sites: Better Education | Better Education Forum
Welcome Guest Search | Active Topics | Members | Log In | Register

C# - Align headings in datagridview Options · View
hong
Posted: Monday, June 28, 2010 7:52:38 PM

Rank: Administration
Groups: Administration

Joined: 11/23/2008
Posts: 335
Points: 711
Location: Australia
We know we can align the cell contents with the following two ways:
1. configure it in design mode
In design mode, select the datagridview, right click mouse and select Edit Columns. Select the column and configure the DefaultCellStyle.

2. by code
Code:
DataGridView1.Columns[1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight


But how to align the header text in datagridview? We have to write a little bit code, see the following examples:
Align the headings of all columns:
Code:
dataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

Align the heading of an individual column:
Code:
deptDataGridViewTextBoxColumn.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;


You need to set the sort mode to not sortable:
Code:
DataGridView1.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable
//Aligns the Header Text
dataGridView1.Columns(1).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight




Sponsor
Posted: Monday, June 28, 2010 7:52:38 PM
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

ASPNET Theme created by Boskone (Dan Ferguson)
Powered by Yet Another Forum.net version 1.9.1.8 (NET v2.0) - 3/29/2008
Copyright © 2003-2008 Yet Another Forum.net. All rights reserved.
This page was generated in 0.049 seconds.