読者です 読者をやめる 読者になる 読者になる

clock-up-blog

go-mi-tech

(.NET) Removing icon on listview column header

Windows C# .NET Framework ListView

Summary

Removing icon on list view column header looks easy, but actually it has confused feature.

Bad code

This code looks no problem but it doesn't work.

ListView view;
int col;
view.Columns[col].ImageIndex = -1;

Good code

You need to re-assign TextAlign property of ColumnHeader instance, then the icon is removed completely.

ListView view;
int col;
view.Columns[col].ImageIndex = -1;
// re-assign alignment then icon is removed completely
view.Columns[col].TextAlign = view.Columns[col].TextAlign;
});