Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I align text for a single subitem in a ListView using C#?

I wasn't able to find an answer anywhere about this seemingly simple topic: is it possible to align text of a single subitem in a WinForms ListView control?

If so, how?

I would like to have text in the same column aligned differently.

like image 260
Fueled Avatar asked Feb 18 '09 16:02

Fueled


2 Answers

example :

listView1.Columns[1].TextAlign = HorizontalAlignment.Right;

will set Column's "1" alignment to right

like image 58
Novpiar Effendi Avatar answered Oct 09 '22 10:10

Novpiar Effendi


Note: Due to a limitation of the underlying native ListView control (living in comctl32.dll), the first column cannot be aligned. It will be always aligned left. The second limitation is when you custom draw (custom draw subitems): when you enable column reordering, the text of the first column is NOT reordered correctly. I solved this limitation (would not call it a bug, because the listview supports many list styles and the internal data structure of a list view is a tree like one) by not allowing to reorder the first column, which in most cases is no problem, because you'll use some sort of key for the first column like number or something similar.

like image 44
Martin.Martinsson Avatar answered Oct 09 '22 11:10

Martin.Martinsson