|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
DataGridView Column AlignmentHi
For numeric columns I want to align it to the right How can I do that? Samuel 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").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight Ken -------------------------------- Show quoteHide quote "Samuel Shulman" <samuel.shul***@ntlworld.com> wrote in message news:%23j9DQDTvGHA.4160@TK2MSFTNGP06.phx.gbl... > Hi > > For numeric columns I want to align it to the right > > How can I do that? > > Samuel > 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=MyHelper.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 Show quoteHide quote > 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").DefaultCellStyle.Alignment > = > DataGridViewContentAlignment.MiddleRight > Ken > -------------------------------- > "Samuel Shulman" <samuel.shul***@ntlworld.com> wrote in message > news:%23j9DQDTvGHA.4160@TK2MSFTNGP06.phx.gbl... >> Hi >> >> For numeric columns I want to align it to the right >> >> How can I do that? >> >> Samuel >> 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 Show quoteHide quote "Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message news:uhVZLgTvGHA.1772@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").DefaultCellStyle.Alignment = > DataGridViewContentAlignment.MiddleRight > > > Ken > -------------------------------- > "Samuel Shulman" <samuel.shul***@ntlworld.com> wrote in message > news:%23j9DQDTvGHA.4160@TK2MSFTNGP06.phx.gbl... >> Hi >> >> For numeric columns I want to align it to the right >> >> How can I do that? >> >> Samuel >> > > On Fri, 11 Aug 2006 15:00:05 +0100, "Samuel Shulman" <samuel.shul***@ntlworld.com> wrote: Me.DataGridView.Columns.Item(Index).HeaderCell.Style.Alignment = _>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 > DataGridViewContentAlignment.MiddleCenter Where Index can be the column index value or the column name string Gene Show quoteHide quote >"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message >news:uhVZLgTvGHA.1772@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").DefaultCellStyle.Alignment = >> DataGridViewContentAlignment.MiddleRight >> >> >> Ken >> -------------------------------- >> "Samuel Shulman" <samuel.shul***@ntlworld.com> wrote in message >> news:%23j9DQDTvGHA.4160@TK2MSFTNGP06.phx.gbl... >>> Hi >>> >>> For numeric columns I want to align it to the right >>> >>> How can I do that? >>> >>> Samuel >>> >> >> >
Can a .NET Web Service be accessed from a VB6 Client?
Is there a statement that will completely empty a listbox? Event handlers Trouble with pixels Quesion about ADO.NET in VB.NET Threading Question Reporting options in vb 2005 How to code image path relative to project Tip of The Day is My.Settings version specific? |
|||||||||||||||||||||||