datagridview check if font is bold

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • coopdog
    New Member
    • Dec 2007
    • 5

    datagridview check if font is bold

    I need to check if fonts are bold or not within each cell. I can easily change the font to bold but I can't seem to get a true/false after I have written to the cell to see if it is bold or not.

    Should this not work?
    If Me.DataGridView 1.Item(x, y).Style.Font.B old Then

    Thanks

    Mike
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Originally posted by coopdog
    Should this not work?
    If Me.DataGridView 1.Item(x, y).Style.Font.B old Then
    What happens when you do that?

    Note, it might be necessary to create a new font object and set it to match the one that's in the cell, then use that. There were cases in VB6 where this is necessary, so maybe it's still hanging around.

    Comment

    • coopdog
      New Member
      • Dec 2007
      • 5

      #3
      Originally posted by Killer42
      What happens when you do that?

      Note, it might be necessary to create a new font object and set it to match the one that's in the cell, then use that. There were cases in VB6 where this is necessary, so maybe it's still hanging around.

      It returns an error for any cell that does not contain bold text.

      I cheated and created a function that will check for bold and catches the error if it is not then returns true or false. Not sure if this is the best solution but it seems to work.

      Thanks for the reply

      Mike

      Comment

      • QVeen72
        Recognized Expert Top Contributor
        • Oct 2006
        • 1445

        #4
        Hi,

        Yes, in VB.net, It works alright if the Font is Bold,
        but if not Bold then you will get Null Reference Exception,
        this is work around.

        [code=vbnet]
        Dim TFlg As Boolean
        Try
        TFlg = DataGridView1.I tem(2, 5).Style.Font.B old
        Catch ex As Exception
        TFlg = False
        End Try
        MsgBox(TFlg)
        [/code]

        Regards
        Veena

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by QVeen72
          Yes, in VB.net, It works alright if the Font is Bold, but if not Bold then you will get Null Reference Exception ...
          Wow! What an amazinlgy stupid language feature. :(

          I hope someday we get a programming language that we can work with instead of around.

          Comment

          • coopdog
            New Member
            • Dec 2007
            • 5

            #6
            Thanks for all the help, that is almost exactly what I came up with in my little function.

            Thanks again

            Mike

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              Shouldn't you be checking the type of exception?

              Comment

              Working...