Click here to Skip to main content
15,889,909 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionDataGridView.Column("name").DefaultCellStyle.Format applied to all columns (it shouldn't be) Pin
Johan Hakkesteegt22-Apr-15 3:06
Johan Hakkesteegt22-Apr-15 3:06 
AnswerRe: DataGridView.Column("name").DefaultCellStyle.Format applied to all columns (it shouldn't be) Pin
Dave Kreskowiak22-Apr-15 4:15
mveDave Kreskowiak22-Apr-15 4:15 
GeneralRe: DataGridView.Column("name").DefaultCellStyle.Format applied to all columns (it shouldn't be) Pin
Johan Hakkesteegt22-Apr-15 20:26
Johan Hakkesteegt22-Apr-15 20:26 
GeneralRe: DataGridView.Column("name").DefaultCellStyle.Format applied to all columns (it shouldn't be) Pin
Johan Hakkesteegt22-Apr-15 21:21
Johan Hakkesteegt22-Apr-15 21:21 
GeneralRe: DataGridView.Column("name").DefaultCellStyle.Format applied to all columns (it shouldn't be) Pin
Dave Kreskowiak23-Apr-15 2:20
mveDave Kreskowiak23-Apr-15 2:20 
GeneralRe: DataGridView.Column("name").DefaultCellStyle.Format applied to all columns (it shouldn't be) Pin
Johan Hakkesteegt23-Apr-15 3:46
Johan Hakkesteegt23-Apr-15 3:46 
GeneralRe: DataGridView.Column("name").DefaultCellStyle.Format applied to all columns (it shouldn't be) Pin
Dave Kreskowiak23-Apr-15 4:05
mveDave Kreskowiak23-Apr-15 4:05 
GeneralRe: DataGridView.Column("name").DefaultCellStyle.Format applied to all columns (it shouldn't be) Pin
Johan Hakkesteegt23-Apr-15 22:21
Johan Hakkesteegt23-Apr-15 22:21 
Hi Dave,

You were right (as usual).

I found that I was calling another method (see below) before using the one I posted originally. When I commented this one out, the first method worked as expected. Looking at it though, I don't see how this method caused the unexpected behavior. As far as I can tell, it is pretty much doing the same thing.
VB
Public Sub FormatTable(ByVal dgv As DataGridView)
        Dim cs_Default As New DataGridViewCellStyle(dgv.DefaultCellStyle)
        Dim cs_Money As New DataGridViewCellStyle(cs_Default)
        Dim cs_Date As New DataGridViewCellStyle(cs_Default)
        Dim cs_String As New DataGridViewCellStyle(cs_Default)
        Dim cs_Integer As New DataGridViewCellStyle(cs_Default)
        Try
            With cs_Date
                .Alignment = DataGridViewContentAlignment.MiddleLeft
            End With
            With cs_Money
                .Alignment = DataGridViewContentAlignment.MiddleRight
                .Format = "F"
            End With
            With cs_Integer
                .Alignment = DataGridViewContentAlignment.MiddleRight
                .Format = "N0"
            End With
            With cs_String
                .Alignment = DataGridViewContentAlignment.MiddleLeft
            End With
            For Each clm As DataGridViewColumn In dgv.Columns
                Select Case clm.ValueType
                    Case Type_Double, Type_Long, Type_Decimal
                        clm.DefaultCellStyle = cs_Money
                    Case Type_Integer
                        clm.DefaultCellStyle = cs_Integer
                    Case Type_String
                        clm.DefaultCellStyle = cs_String
                End Select
            Next
        Catch ex As Exception
            EC(ex)
        End Try
    End Sub

Regards,
Johan
My advice is free, and you may get what you paid for.

GeneralRe: DataGridView.Column("name").DefaultCellStyle.Format applied to all columns (it shouldn't be) Pin
Dave Kreskowiak24-Apr-15 3:49
mveDave Kreskowiak24-Apr-15 3:49 
GeneralRe: DataGridView.Column("name").DefaultCellStyle.Format applied to all columns (it shouldn't be) Pin
Johan Hakkesteegt24-Apr-15 4:03
Johan Hakkesteegt24-Apr-15 4:03 
AnswerRe: DataGridView.Column("name").DefaultCellStyle.Format applied to all columns (it shouldn't be) Pin
Eddy Vluggen22-Apr-15 4:51
professionalEddy Vluggen22-Apr-15 4:51 
GeneralRe: DataGridView.Column("name").DefaultCellStyle.Format applied to all columns (it shouldn't be) Pin
Johan Hakkesteegt22-Apr-15 20:31
Johan Hakkesteegt22-Apr-15 20:31 
GeneralRe: DataGridView.Column("name").DefaultCellStyle.Format applied to all columns (it shouldn't be) Pin
Eddy Vluggen22-Apr-15 22:38
professionalEddy Vluggen22-Apr-15 22:38 
QuestionUnsure How to Approach New Personal Project Pin
cyberphreak198121-Apr-15 7:06
cyberphreak198121-Apr-15 7:06 
AnswerRe: Unsure How to Approach New Personal Project Pin
Sascha Lefèvre21-Apr-15 7:24
professionalSascha Lefèvre21-Apr-15 7:24 
GeneralRe: Unsure How to Approach New Personal Project Pin
cyberphreak198121-Apr-15 7:27
cyberphreak198121-Apr-15 7:27 
GeneralRe: Unsure How to Approach New Personal Project Pin
Sascha Lefèvre21-Apr-15 7:36
professionalSascha Lefèvre21-Apr-15 7:36 
GeneralRe: Unsure How to Approach New Personal Project Pin
cyberphreak198121-Apr-15 7:40
cyberphreak198121-Apr-15 7:40 
GeneralRe: Unsure How to Approach New Personal Project Pin
Sascha Lefèvre21-Apr-15 8:34
professionalSascha Lefèvre21-Apr-15 8:34 
QuestionEntity framework : How to get DBcontext.ChangeTracker.Entries(of ???)) for a class known only at runtime Pin
dilkonika20-Apr-15 18:22
dilkonika20-Apr-15 18:22 
AnswerRe: Entity framework : How to get DBcontext.ChangeTracker.Entries(of ???)) for a class known only at runtime Pin
Dave Kreskowiak21-Apr-15 1:50
mveDave Kreskowiak21-Apr-15 1:50 
QuestionContinue to next step in a for..next loop only when the user press a button. Pin
dilkonika18-Apr-15 17:59
dilkonika18-Apr-15 17:59 
AnswerRe: Continue to next step in a for..next loop only when the user press a button. Pin
PIEBALDconsult18-Apr-15 18:52
mvePIEBALDconsult18-Apr-15 18:52 
GeneralRe: Continue to next step in a for..next loop only when the user press a button. Pin
dilkonika18-Apr-15 19:01
dilkonika18-Apr-15 19:01 
GeneralRe: Continue to next step in a for..next loop only when the user press a button. PinPopular
PIEBALDconsult18-Apr-15 19:21
mvePIEBALDconsult18-Apr-15 19:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.