We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

number of characters vs. number of pixels

Hi, I use the latest version of GGC. The GridColumnDescriptor.Width returns a value represents number of pixels. Instead of pixels, how to get the value in number of characters? Thanks, NJ

1 Reply

AD Administrator Syncfusion Team September 28, 2005 11:07 PM UTC

Hi Nj, there is no precise way to convert from pixels to characters unless you do a use a fixed font and not a propertional font. An estimate can calculated with Graphics g; int charWidth = (int) g.MeasureString("Abc", font).Width/3; and then divide the column.width with charWith. You can also determine the maximum length of characters found in the column using the GridTable.GetColumnMaxLength(columnDescriptor) method. If you do not explicitly set a column.Width then the grid will actually automatically size the column by calling GridTable.GetColumnMaxLength and then multiply this with the same charWidth used above. This is done within the GridTable.GetPreferredColumnWidth(columnDescriptor) method. Stefan >Hi, > > I use the latest version of GGC. The GridColumnDescriptor.Width returns a value represents number of pixels. Instead of pixels, how to get the value in number of characters? > >Thanks, >NJ

Loader.
Live Chat Icon For mobile
Up arrow icon