10

I have a Listview in detail mode with 3 columns. I want to set the text align for the headers to "center". This works for the last two columns but not for the first. If I want to change it to "center" and click on "center", the field keeps being set to "left". Can I change this using the properties or do I need to program this?

Thanks.

benst
  • 553
  • 2
  • 12
  • 32

3 Answers3

18

According to the documentation:

Due to a limitation in the underlying control, this property has no effect on the first column in the ListView control, which is always aligned to the left. To work around this limitation in .NET Framework version 2.0, you can handle the ListView.DrawColumnHeader event and paint the column header yourself.

Another alternative workaround is to not use the first column at all and hide it by setting its width to zero.

Antagony
  • 1,750
  • 12
  • 17
5

I have got a simple solution: Add a new (not needed) first column. Change the alignment of the second column (your real first column) to right or center (can now be done in the designer). In Form-Load-Event remove the first (temporary) column. Voila - the textalignent now should be correct.

I have testet this behavior under Windows 7, 8.1 and 10. It should work.

greetings from germany

1

I realize this is an old post, but I just found another workaround. If you insert whitespaces just before the header text you are inserting or changing in your code (I know it's rough and you need to calculate how many spaces gets your header centered, but it works!) then you can alter the position of the first column's (0) header text as follows:

ListView2.Columns(0).Text = "                              " & ListView1.SelectedItems(0).Text.ToString