Display numbers in HEX - DataGridView?
-
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
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) -
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) -
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
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) -
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
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