If a column is added to a list-view control with index 0 (the leftmost column) and with LVCFMT_RIGHT or LVCFMT_CENTER specified, the text is not right-aligned or centered. The text in the index 0 column is left-aligned. Therefore if you keep inserting columns with index 0, the text in all columns are left-aligned. If you want the first column to be right-aligned or centered you can make a dummy column, then insert one or more columns with index 1 or higher and specify the alignment you require. Finally delete the dummy column.
==========================================================================================
十分感谢!
可是如果只是插入文本的话,是好用的,我给加入一个Image List后就不好用了。
这个CListCtrl真是麻烦!
这是俺的代码,大侠帮给看看:
//插入一些colomn先,然后
m_list.SetImageList(&m_Image,LVSIL_SMALL);
m_list.DeleteColumn(0);
m_list.InsertItem(0, " ");//默认就给第一列加上图像了,我考
m_list.SetItem(0,0,LVIF_IMAGE,NULL,-1,0,0,0);//把第一列图像去掉
m_list.SetItemText(0,0, "hahaha ");
结果header居中了,可是“hahaha”并没有居中,是在中间偏右的地方,你点它,他还会往左动一下,我真是服了。什么乱七八糟的。
==========================================================================================
LVCOLUMN lv_column;
memset(&lv_column,0,sizeof(LVCOLUMN));
lv_column.mask = LVCF_TEXT | LVCF_FMT;
m_list.SetExtendedStyle( LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT );
for( int i=0 ; i <6 ; i++ )
{
lv_column.fmt = LVCFMT_CENTER;
}
=======================================================
m_list.DeleteColumn(0);
应该放在操作的最后