Creating a custom format string in a dataGridView

Posted by Andy on Stack Overflow See other posts from Stack Overflow or by Andy
Published on 2010-04-26T18:03:29Z Indexed on 2010/04/26 18:13 UTC
Read the original article Hit count: 209

Filed under:
|
|

I have a dataGridView whose dataSource is a dataTable.

My problem is that I want certain columns to be displayed in Hex. I can get that far with using something like this:

 foreach (DataGridViewColumn c in grid.Columns)
        {
            if (DISPLAYED_IN_HEX.Contains(c.Name))
            {
                c.DefaultCellStyle.Format = "X";

            }
        }

My issue though is that I want this hex value prepended with 0x so as not to confuse anyone that they are in hexidecimal form. The values in the dataTable are various integral types. I looked into creating a custom IFormatProvider, but I don't think my coding skills are up to that par yet. Any other possible solutions?

© Stack Overflow or respective owner

Related posts about c#

Related posts about formatting