Search code examples
c#compact-frameworkwindows-ce

Adapt column width of a Listview to its content


I load a listview with several items and I would like to adapt the width of the listview to its content. Unfortunately, this doesn't work. I'm working on windows CE with the compact Framework .NET and I've already tried to set the width of the column to "-1" and "-2" as mentionned on MSDN. But no result so far...

Does anyone could help me on that...


Solution

  • According to the [MSDN page] on column widths:

    This property enables you to set the Width of the ColumnHeader. The ColumnHeader can be set to adjust at run time to the column contents or heading. To adjust the width of the longest item in the column, set the Width property to -1. To autosize to the width of the column heading, set the Width property to -2

    For your purposes you should be setting the column width to -1. Note that you will have to do this after adding the items to the list.