解决CListCtrl中第一列元素的只有左对齐问题的两种方法?
来源:互联网 发布:淘宝怎么判断质量问题 编辑:程序博客网 时间:2024/05/08 22:03
问题:在CListCtrl中第一列元素只能左对齐,下面是msdn中的说明!
CListCtrl::InsertColumn
Inserts a new column in a list view control.
int InsertColumn(
int nCol,
const LVCOLUMN* pColumn
);
int InsertColumn(
int nCol,
LPCTSTR lpszColumnHeading,
int nFormat = LVCFMT_LEFT,
int nWidth = -1,
int nSubItem = -1
);
Parameters
nCol
The index of the new column.
pColumn
Address of an LVCOLUMN structure that contains the attributes of the new column.
lpszColumnHeading
Address of a string containing the column's heading.
nFormat
Integer specifying the alignment of the column. It can be one of these values: LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER.
nWidth
Width of the column, in pixels. If this parameter is -1, the column width is not set.
nSubItem
Index of the subitem associated with the column. If this parameter is -1, no subitem is associated with the column.
Return Value
The index of the new column if successful or -1 otherwise.
Remarks
The leftmost column in a list view control must be left-aligned.
The LVCOLUMN structure contains the attributes of a column in report view. It is also used to receive information about a column. This structure is described in the Platform SDK.
解决方法:
方法1:
1、在第一列插入一个空列
2、设置第一列的宽度为0
3、然后插入位置从1开始
例子代码:
m_pListCtrl.InsertColumn (0, "",LVCFMT_CENTER);
m_pListCtrl.InsertColumn (1, "Element",LVCFMT_LEFT);
m_pListCtrl.InsertColumn (2, "Note",LVCFMT_LEFT);
m_pListCtrl.SetColumnWidth (0, 0);
m_pListCtrl.SetColumnWidth (1, ClientRect.Width() / 5);
m_pListCtrl.SetColumnWidth (2, LVSCW_AUTOSIZE_USEHEADER);
方法2:
1、首先多添加一列
2、当所有列添加完成以后,删除第一列即可
例子代码:
m_List.InsertColumn (0, "dummy", LVCFMT_CENTER); //多添加一列
m_List.InsertColumn (1, "Element", LVCFMT_CENTER);
m_List.InsertColumn (2, "Note", LVCFMT_LEFT);
m_List.DeleteColumn(0);
m_List.SetColumnWidth (0, ClientRect.Width() / 5);
m_List.SetColumnWidth (1, LVSCW_AUTOSIZE_USEHEADER);
- 解决CListCtrl中第一列元素的只有左对齐问题的两种方法?
- CListCtrl第一列不能设置对齐方式的解决办法
- 解决Qt中,只有鼠标左键处于单击状态时才会捕捉mouseMoveEvent的问题
- 解决CCPageTurn3D只有往左翻页的问题
- (摘抄)VB中按钮控件的左对齐方法
- 横向两列布局(左列固定,右列自适应)的4中实现方式
- LI 标签中让文章标题左对齐,日期右对齐的方法
- LI 标签中让文章标题左对齐,日期右对齐的方法
- html中怎么将标签左对齐,而文本框右对齐的方法
- c++中关于设置左对齐和右对齐的问题解决方法
- CListCtrl删除多行的两种方法
- VC中CListCtrl删除所有的列
- treeview子节点的左对齐问题
- ios中UISearchBar的placeHolder左对齐
- ADC左对齐与右对齐的数据读取问题
- Visio画ER图时显示只有两列的问题
- 解决easyui表格加载时候的列标题和列内容无法严格对齐的问题!
- MFC中的CListCtrl的最左边一列必须左对齐吗?
- 用来用去还是感觉Eclipse3 + 中文语言包 + lomboz.301 + jrun4(weblogic 8) 开发J2EE 比较顺利~
- 害怕
- 动态include文件
- VBScript函数速查
- 今天用Eclipse3 + 中文语言包 + lomboz.301 + jrun4 测试成功了 J2EE1.4TutorialTranslation中的Cart的例子了。
- 解决CListCtrl中第一列元素的只有左对齐问题的两种方法?
- 动态链接库的创建和调用
- Web打印代码
- Eclipse 平台入门
- 原创串口类库v2的使用范例,很简单,高手勿入
- 电脑前的护眼窍门
- 本周计划
- C++编程人员容易犯的10个C#错误
- 动态连结库调用char * 返回空的解决办法