473,387 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

DataGridView Column Alignment

Hi

For numeric columns I want to align it to the right

How can I do that?

Samuel
Aug 11 '06 #1
4 25839
Hi,

Change the alignment of the default cell style for the column.

Dim strConn As String
Dim da As SqlDataAdapter
Dim conn As SqlConnection

strConn = "Server = .;Database = AdventureWorks; Integrated Security
= SSPI;"
conn = New SqlConnection(strConn)

da = New SqlDataAdapter("Select * from HumanResources.Employee",
conn)

da.Fill(ds, "Employee")
DataGridView1.DataSource = ds.Tables("Employee")
DataGridView1.Columns("ContactID").DefaultCellStyl e.Alignment =
DataGridViewContentAlignment.MiddleRight
Ken
--------------------------------
"Samuel Shulman" <sa************@ntlworld.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
Hi

For numeric columns I want to align it to the right

How can I do that?

Samuel

Aug 11 '06 #2
In my solution, I have included a helper class to encapsulate some of these
standard settings. In that class, I have a function which gets a standardized
(for my application) currency formatter as follows:

Public Function DGCurrencyStyle() As DataGridViewCellStyle
Dim Style As New DataGridViewCellStyle
Style.Alignment = DataGridViewContentAlignment.MiddleRight
Style.Format = "c2"
Return Style
End Function

To use it, I modify the .Designer file and set the DataGridViewTextBoxColumn1.DefaultCellStyle=MyHelp er.DGCurrencyStyle.
This way, if I want to change the style throughout my system, I just change
it in the helper and the change is reflected throughout the system.

Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx
Hi,

Change the alignment of the default cell style for the column.

Dim strConn As String
Dim da As SqlDataAdapter
Dim conn As SqlConnection
strConn = "Server = .;Database = AdventureWorks; Integrated
Security
= SSPI;"
conn = New SqlConnection(strConn)
da = New SqlDataAdapter("Select * from
HumanResources.Employee", conn)

da.Fill(ds, "Employee")
DataGridView1.DataSource = ds.Tables("Employee")
DataGridView1.Columns("ContactID").DefaultCellStyl e.Alignment
=
DataGridViewContentAlignment.MiddleRight
Ken
--------------------------------
"Samuel Shulman" <sa************@ntlworld.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>Hi

For numeric columns I want to align it to the right

How can I do that?

Samuel

Aug 11 '06 #3
Thank you,

The actual column header remains on the left and in ListView control it
moves to the right like the content of the list

I am actually not sure what would be the correct way but is there a way of
changing that as well?

Samuel

"Ken Tucker [MVP]" <vb***@bellsouth.netwrote in message
news:uh**************@TK2MSFTNGP06.phx.gbl...
Hi,

Change the alignment of the default cell style for the column.

Dim strConn As String
Dim da As SqlDataAdapter
Dim conn As SqlConnection

strConn = "Server = .;Database = AdventureWorks; Integrated
Security = SSPI;"
conn = New SqlConnection(strConn)

da = New SqlDataAdapter("Select * from HumanResources.Employee",
conn)

da.Fill(ds, "Employee")
DataGridView1.DataSource = ds.Tables("Employee")
DataGridView1.Columns("ContactID").DefaultCellStyl e.Alignment =
DataGridViewContentAlignment.MiddleRight
Ken
--------------------------------
"Samuel Shulman" <sa************@ntlworld.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>Hi

For numeric columns I want to align it to the right

How can I do that?

Samuel


Aug 11 '06 #4
On Fri, 11 Aug 2006 15:00:05 +0100, "Samuel Shulman" <sa************@ntlworld.comwrote:
>Thank you,

The actual column header remains on the left and in ListView control it
moves to the right like the content of the list

I am actually not sure what would be the correct way but is there a way of
changing that as well?

Samuel

Me.DataGridView.Columns.Item(Index).HeaderCell.Sty le.Alignment = _
DataGridViewContentAlignment.MiddleCenter

Where Index can be the column index value or the column name string
Gene
>"Ken Tucker [MVP]" <vb***@bellsouth.netwrote in message
news:uh**************@TK2MSFTNGP06.phx.gbl...
>Hi,

Change the alignment of the default cell style for the column.

Dim strConn As String
Dim da As SqlDataAdapter
Dim conn As SqlConnection

strConn = "Server = .;Database = AdventureWorks; Integrated
Security = SSPI;"
conn = New SqlConnection(strConn)

da = New SqlDataAdapter("Select * from HumanResources.Employee",
conn)

da.Fill(ds, "Employee")
DataGridView1.DataSource = ds.Tables("Employee")
DataGridView1.Columns("ContactID").DefaultCellStyl e.Alignment =
DataGridViewContentAlignment.MiddleRight
Ken
--------------------------------
"Samuel Shulman" <sa************@ntlworld.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>>Hi

For numeric columns I want to align it to the right

How can I do that?

Samuel

Aug 11 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Peter | last post by:
How to I changed bound column in DataGridView from DataGridViewTextBoxColumn(); to DataGridViewButtonColumn() ? Thanks Peter
5
by: bob | last post by:
Now this ought to be a simple matter. But nothing's simple in the Net world, I'm finding. In vb6 you could use "!" to force text to upper case in the format function. I've searched the vb.net...
1
by: martin1 | last post by:
Hi, All, DataGridView is populated with all coumns from database since i need some columns data for condition statement, after that I want to show rest of column in the DataGridView, so how to...
3
by: martin1 | last post by:
All, ..Net 2.0 DataGridView column sort is automatic, I don't want column sort, is anybody know how to not sort column in DataGridView? Thanks
0
by: Mike | last post by:
Hey everyone... I've got three problems with a custom DataGridView column I've built following the "How To: Host Controls in Windows Forms DataGridView Cells" article. The base editing control...
1
by: Chalkie | last post by:
Hello, I've hit what appears to be a serious problem with an unbound datagridview control that Ive added to a VB.Net program. Inadvertently I named one column 'Name' and a second 'Size'. The...
0
by: sk27ahmed | last post by:
Hi Any one can show me how to access datagridview column value on column checked unchecked. I create one column in datagridview of type checkbox,and on button click i write code to select all...
2
by: Steve | last post by:
Hi All I am using VB.net 2005 windows forms I use the Datagridview.cellformatting event to change the colours of individual cells as required and all works fine How can I do the same for...
0
by: lenniekuah | last post by:
Hi Fellow Good Guys, I need your help, Please Help me. Surprising I encounterd another problem which never happened in VB.NET but in C# technique it causing problem. Here is the explanation...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.