Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Display numbers in HEX - DataGridView?

Display numbers in HEX - DataGridView?

Scheduled Pinned Locked Moved C#
csharpquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    liqnit
    wrote on last edited by
    #1

    Hi I am using VS2008 C# with datagridview and filling the cells using a byte[]. Is there a away the cells will display the value in HEX ? Thanks

    Have a nice Day

    D 1 Reply Last reply
    0
    • L liqnit

      Hi I am using VS2008 C# with datagridview and filling the cells using a byte[]. Is there a away the cells will display the value in HEX ? Thanks

      Have a nice Day

      D Offline
      D Offline
      DaveyM69
      wrote on last edited by
      #2

      Register for the CellFormatting[^] event and do the conversion for display there

      Dave
      BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
      Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

      L 1 Reply Last reply
      0
      • D DaveyM69

        Register for the CellFormatting[^] event and do the conversion for display there

        Dave
        BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
        Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

        L Offline
        L Offline
        liqnit
        wrote on last edited by
        #3

        thanks a lot . Maybe i am missing somthing is therea way of not converting to string and display the value as Hex Thanks

        Have a nice Day

        D D 2 Replies Last reply
        0
        • L liqnit

          thanks a lot . Maybe i am missing somthing is therea way of not converting to string and display the value as Hex Thanks

          Have a nice Day

          D Offline
          D Offline
          DaveyM69
          wrote on last edited by
          #4

          A simple method like this should do it:

          public string ToHexstring(byte[] byteArray)
          {
          if (byteArray.Length > 0)
          {
          StringBuilder resultBuilder = new StringBuilder();
          foreach (byte value in byteArray)
          resultBuilder.Append(value.ToString("X2"));
          return resultBuilder.ToString();
          }
          else
          return "00";
          }

          Dave
          BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
          Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

          1 Reply Last reply
          0
          • L liqnit

            thanks a lot . Maybe i am missing somthing is therea way of not converting to string and display the value as Hex Thanks

            Have a nice Day

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            The mear fact that a number is being displayed in the DGV makes the item you see in the DGV cell a string, no matter what the actual data type is. So, no there's no way of displayed any data in a DGV without converting it to a string, or some other custom rendered display.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups