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.
Up arrow icon