Search code examples
c#listview

ListView ColumnHeader.Name is empty string


I've created a WinForms ListView as Detail view with four columns. I've given each column a name in the designer, however when accessing each ColumnHeader via the ListView.Columns property, I find each ColumnHeader.Name is an empty string. Am I doing something wrong or is this a framework bug?


Solution

  • I'm able to recreate the same behaviour. I think it must definitely be a bug as it's implied that the value will be set correctly by the designer.

    As a workaround, you could put the name into the Tag property too. (Or set it programmatically in the constructor, but that won't work well if you need to add a column in the designer later on. I would then rather go with not using the designer at all to initialize the columns.)

    I found some discussion on this here - looks like this is a known issue, they are also going with the Tag hack.