MFC的list control控件插入数据后只能显示第一列??
m_teachers.InsertColumn(0,"姓名",LVCFMT_LEFT,40);m_teachers.InsertColumn(1,"年龄",LVCFMT_...
m_teachers.InsertColumn(0, "姓名", LVCFMT_LEFT, 40);
m_teachers.InsertColumn(1, "年龄", LVCFMT_LEFT, 40);
m_teachers.InsertItem(0,"admin");
m_teachers.SetItemText(0,1,"20");
m_teachers.InsertItem(1,"admin0");
m_teachers.SetItemText(1,1,"20");
m_teachers.InsertItem(2,"admin1");
m_teachers.SetItemText(2,1,"21");
插入数据后只能显示第一列????IDE是vc6 展开
m_teachers.InsertColumn(1, "年龄", LVCFMT_LEFT, 40);
m_teachers.InsertItem(0,"admin");
m_teachers.SetItemText(0,1,"20");
m_teachers.InsertItem(1,"admin0");
m_teachers.SetItemText(1,1,"20");
m_teachers.InsertItem(2,"admin1");
m_teachers.SetItemText(2,1,"21");
插入数据后只能显示第一列????IDE是vc6 展开
2个回答
展开全部
下面是个如何使用ClisCtrl控件的例子:
CListCtrl& ListCtrl = GetListCtrl();
LV_COLUMN lvc;
TCHAR *arrTitle[] = {"基本信息", "名称", "代码", "均价", "数目", "...", "...", "...", "..."};
UCHAR nWidth[] = {200, 100, 100, 60, 80, 60, 80, 60, 100};
USHORT nFMT[] = {LVCFMT_LEFT, LVCFMT_CENTER, LVCFMT_CENTER, LVCFMT_RIGHT, LVCFMT_RIGHT, LVCFMT_RIGHT, LVCFMT_RIGHT, LVCFMT_CENTER, LVCFMT_RIGHT};
m_nColumnNum = 0;
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
for (int i = 0; i < sizeof(nWidth) / sizeof(UCHAR); i ++)
{
lvc.iSubItem = i;
lvc.pszText = arrTitle[i];
lvc.cx = nWidth[i];
lvc.fmt = nFMT[i];
ListCtrl.InsertColumn(i, &lvc);
m_nColumnNum ++;
}
LV_ITEM lvItem;
int nIndex = 0;
CString strInsertText;
double nTotalProfit = 0;
POSITION curPos;
CStockList *pCurrentStockCode;
TCHAR buff[32];
curPos = m_listExchangedStock.GetHeadPosition();
while (curPos != NULL)
{
....
lvItem.mask = LVIF_TEXT | LVIF_PARAM;
lvItem.iItem = nIndex ++;
lvItem.lParam = NULL;
buff[0] = 0;
lvItem.pszText = buff;
lvItem.iSubItem = 0;
ListCtrl.InsertItem(&lvItem);
lvItem.iSubItem = 1;
lvItem.mask = LVIF_TEXT;
sprintf_s(buff, "%s", pCurrentStockCode->m_cStockName);
ListCtrl.SetItem(&lvItem);
lvItem.iSubItem = 2;
lvItem.mask = LVIF_TEXT;
sprintf_s(buff, "%06d", pCurrentStockCode->m_nStockCode);
ListCtrl.SetItem(&lvItem);
CListCtrl& ListCtrl = GetListCtrl();
LV_COLUMN lvc;
TCHAR *arrTitle[] = {"基本信息", "名称", "代码", "均价", "数目", "...", "...", "...", "..."};
UCHAR nWidth[] = {200, 100, 100, 60, 80, 60, 80, 60, 100};
USHORT nFMT[] = {LVCFMT_LEFT, LVCFMT_CENTER, LVCFMT_CENTER, LVCFMT_RIGHT, LVCFMT_RIGHT, LVCFMT_RIGHT, LVCFMT_RIGHT, LVCFMT_CENTER, LVCFMT_RIGHT};
m_nColumnNum = 0;
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
for (int i = 0; i < sizeof(nWidth) / sizeof(UCHAR); i ++)
{
lvc.iSubItem = i;
lvc.pszText = arrTitle[i];
lvc.cx = nWidth[i];
lvc.fmt = nFMT[i];
ListCtrl.InsertColumn(i, &lvc);
m_nColumnNum ++;
}
LV_ITEM lvItem;
int nIndex = 0;
CString strInsertText;
double nTotalProfit = 0;
POSITION curPos;
CStockList *pCurrentStockCode;
TCHAR buff[32];
curPos = m_listExchangedStock.GetHeadPosition();
while (curPos != NULL)
{
....
lvItem.mask = LVIF_TEXT | LVIF_PARAM;
lvItem.iItem = nIndex ++;
lvItem.lParam = NULL;
buff[0] = 0;
lvItem.pszText = buff;
lvItem.iSubItem = 0;
ListCtrl.InsertItem(&lvItem);
lvItem.iSubItem = 1;
lvItem.mask = LVIF_TEXT;
sprintf_s(buff, "%s", pCurrentStockCode->m_cStockName);
ListCtrl.SetItem(&lvItem);
lvItem.iSubItem = 2;
lvItem.mask = LVIF_TEXT;
sprintf_s(buff, "%06d", pCurrentStockCode->m_nStockCode);
ListCtrl.SetItem(&lvItem);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询