LoveBeyond

怎样使CListctrl第一列中的各项居中显示

我的代码: 
m_list.InsertColumn(0, "1 ",LVCFMT_CENTER,80); 
m_list.InsertColumn(1, "2 ",LVCFMT_CENTER,80); 
m_list.InsertColumn(2, "3 ",LVCFMT_CENTER,80); 

m_list.InsertItem(0, "aaa "); 
m_list.SetItemText(0,1, "bbb "); 
m_list.SetItemText(0,2, "ccc "); 

m_list.InsertItem(1, "xxx "); 
m_list.SetItemText(1,1, "yyy "); 
m_list.SetItemText(1,2, "zzz "); 

同样是“LVCFMT_CENTER”,为什么第二列和第三列都能居中,可第一列实际显示就是偏左呢?
==========================================================================================
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); 
应该放在操作的最后

posted on 2011-11-15 19:12 LoveBeyond 阅读(3124) 评论(0)  编辑 收藏 引用

<2011年11月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

导航

统计

留言簿(1)

文章分类

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜

友情链接:C++博客 LoveBeyond 代码疯子 程序人生 C++技术博客