Auto Fit

 
Company Name
Phone
Address
City
Country
Exotic Liquids (171) 555-2222 49 Gilbert St. London UK
New Orleans Cajun Delights (100) 555-4822 P.O. Box 78934 New Orleans USA
Grandma Kelly's Homestead (313) 555-5735 707 Oxford Rd. Ann Arbor USA
Tokyo Traders (03) 3555-5011 9-8 Sekimai Musashino-shi Tokyo Japan
Cooperativa de Quesos 'Las Cabras' (98) 598 76 54 Calle del Rosal 4 Oviedo Spain
Mayumi's (06) 431-7877 92 Setsuko Chuo-ku Osaka Japan
Pavlova, Ltd. (03) 444-2343 74 Rose St. Moonie Ponds Melbourne Australia
Specialty Biscuits, Ltd. (161) 555-4448 29 King's Way Manchester UK
PB Knäckebröd AB 031-987 65 43 Kaloadagatan 13 Göteborg Sweden
Refrescos Americanas LTDA (11) 555 4640 Av. das Americanas 12.890 Sao Paulo Brazil

Call the AutoFitColumnWidths method to match column width values to actual content.

This method takes header, data cell, and summary value content into account. The auto fit algorithm uses the same units as the column's Width property value.

  • If a column's width is set in pixels, the final width is in pixels. The column's width fits its content.
  • If a column's widths is set in percentages or not set, the final width is in percentages. Columns may shrink or grow based on available space.

Depending on calculated values, the following outcomes are possible:

  • Columns occupy the entire width of the component. Example: all or several widths are in percentages.
  • A scroll bar appears. Example: all widths are in pixels and the content is too wide.
  • Empty space remains. Example: all widths are in pixels and the content is not wide enough.

In this demo, the Company Name, selection, and command columns have their width specified in pixels, and their content is always fully visible. The Address column's width is not specified, so it may narrow but not less than its MinWidth (120 pixels).