ListView ColumnHeader.Name - empty string.

I created WinForms ListView as a detailed view with four columns. I gave each column a name in the constructor, however, when accessing each ColumnHeader using the ListView.Columns property, I found that each ColumnHeader.Name is an empty string. Am I doing something wrong or is it a structure error?

+6
c # listview
source share
2 answers

I can recreate the same behavior. I think this will definitely be a mistake, as it implies that the value will be set correctly by the designer.

As a workaround, you can put the name in the Tag property. (Or install it programmatically in the constructor, but this will not work if you need to add a column to the constructor later. Then I would rather not use the constructor at all to initialize the columns.)

I found some discussion of this here - it looks like this is a known issue, they also come with the hack tag.

+6
source share

I had the same problem, but I worked on it as follows:

 foreach (ColumnHeader CN in listView1.Columns) { //I added listbox for this example, but my code uses it //to populate an excell spreadsheet listBox1.Items.Add(CN.Text.ToString()); } 

Hope you can use it in some way.

-one
source share

All Articles