读书人

怎么给ListCtrl控件在指定的位置动态追

发布时间: 2012-01-18 00:23:26 作者: rapoo

如何给ListCtrl控件在指定的位置动态追加一列
如何给ListCtrl控件在指定的位置动态追加一列(急)

[解决办法]
CListCtrl::InsertColumn
int InsertColumn( int nCol, const LVCOLUMN* pColumn );

int InsertColumn( int nCol, LPCTSTR lpszColumnHeading, int nFormat = LVCFMT_LEFT, int nWidth = -1, int nSubItem = -1 );

Return Value

The index of the new column if successful or -1 otherwise.

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 associatied with the column.

Remarks

Inserts a new column in a list view control.

TheLVCOLUMN 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.


[解决办法]
正好有代码:

LV_COLUMN lvcol;

lvcol.mask=LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT|LVCF_WIDTH;
lvcol.fmt=LVCFMT_LEFT;//居中
int i=0;
lvcol.pszText="1";
lvcol.iSubItem=i;
lvcol.cx=40;
m_listCtrl.InsertColumn(i++,&lvcol);
lvcol.pszText="2";
lvcol.cx=50;
m_listCtrl.InsertColumn(i++,&lvcol);
lvcol.pszText="3";
lvcol.cx=60;
m_listCtrl.InsertColumn(i++,&lvcol);
lvcol.pszText="4";
lvcol.cx=40;
m_listCtrl.InsertColumn(i++,&lvcol);
lvcol.pszText="5";
lvcol.cx=80;
m_listCtrl.InsertColumn(i++,&lvcol);

[解决办法]
自己的代码,你看看有没有参考价值,多看msdn
m_listctrl2.InsertColumn(0 , "评估内容", LVCFMT_CENTER, 80, 0 );
m_listctrl2.InsertColumn(1 , " ", LVCFMT_LEFT, 300, 1 );
m_listctrl2.InsertColumn(2 , "权重", LVCFMT_CENTER, 80, 2 );
m_listctrl2.ModifyStyle( LVS_TYPEMASK,LVS_REPORT | LVS_SINGLESEL );
m_listctrl2.SetExtendedStyle( LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES |LVS_EX_HEADERDRAGDROP | LVS_EX_ONECLICKACTIVATE );

读书人网 >VC/MFC

热点推荐