How to show file size in kb in dataGrid
-
In datagrid i want to show size of file in kb. I have it size in bytes but i want to show it as 2kB. how can i do this
-
In datagrid i want to show size of file in kb. I have it size in bytes but i want to show it as 2kB. how can i do this
-
In datagrid i want to show size of file in kb. I have it size in bytes but i want to show it as 2kB. how can i do this
Use a code behind method like this one - protected string FormatBytes(double bytes) { double gigabyte = 1024 * 1024 * 1024; double megabyte = 1024 * 1024; double kilobyte = 1024; if (bytes > gigabyte) { return string.Format("{0:#,###,###.00} GB", (bytes / gigabyte)); } else if (bytes > megabyte) { return string.Format("{0:#,###.00} MB", (bytes / megabyte)); } else if (bytes > kilobyte) { return string.Format("{0:#,###.00} KB", (bytes / kilobyte)); } else { return string.Format("{0:#,###} B", bytes); } } Then on your column item template use somthing like this - This should do the trick! Kind Regards Ian Claxton C# is for life not just for christmas
-
Use a code behind method like this one - protected string FormatBytes(double bytes) { double gigabyte = 1024 * 1024 * 1024; double megabyte = 1024 * 1024; double kilobyte = 1024; if (bytes > gigabyte) { return string.Format("{0:#,###,###.00} GB", (bytes / gigabyte)); } else if (bytes > megabyte) { return string.Format("{0:#,###.00} MB", (bytes / megabyte)); } else if (bytes > kilobyte) { return string.Format("{0:#,###.00} KB", (bytes / kilobyte)); } else { return string.Format("{0:#,###} B", bytes); } } Then on your column item template use somthing like this - This should do the trick! Kind Regards Ian Claxton C# is for life not just for christmas
Thanks it's work :)