有如下代码,可是有最后一个记录可以显示,前面的全是空的,如果把m_pList->SetItemText()中的index设为0,则可以正常显示。难道insertItem()是插在前面的? 相同的代码在另一个程序中能正常?这是为什么?还是在m_pList->Create()时可以指定插入头还是尾? 其中m_OFDataSet是由CRecordset类派生的一个类的实例。
while(!m_OFDataSet->IsEOF())
{
m_pList->InsertItem(index,"");
m_pList->SetItemText(index,0,m_OFDataSet->m_a1);
m_pList->SetItemText(index,1,m_OFDataSet->m_a2);
m_pList->SetItemText(index,2,m_OFDataSet->m_a3);
m_pList->SetItemText(index,3,m_OFDataSet->m_a4);
m_pList->SetItemText(index,4,m_OFDataSet->m_a5);
m_pList->SetItemText(index,5,m_OFDataSet->m_a6);
m_pList->SetItemText(index,6,m_OFDataSet->m_a7);
m_pList->SetItemText(index,7,m_OFDataSet->m_a8);
// m_pList->SetItemText(index,1,m_OFDataSet->m_a1);
index++;
m_OFDataSet->MoveNext();
}
while(!m_OFDataSet->IsEOF())
{
m_pList->InsertItem(index,"");
m_pList->SetItemText(index,0,m_OFDataSet->m_a1);
m_pList->SetItemText(index,1,m_OFDataSet->m_a2);
m_pList->SetItemText(index,2,m_OFDataSet->m_a3);
m_pList->SetItemText(index,3,m_OFDataSet->m_a4);
m_pList->SetItemText(index,4,m_OFDataSet->m_a5);
m_pList->SetItemText(index,5,m_OFDataSet->m_a6);
m_pList->SetItemText(index,6,m_OFDataSet->m_a7);
m_pList->SetItemText(index,7,m_OFDataSet->m_a8);
// m_pList->SetItemText(index,1,m_OFDataSet->m_a1);
index++;
m_OFDataSet->MoveNext();
}
解决方案 »
- 如何确定磁盘驱动器的名字跟\PhysicalDriveX之间的关系
- 函数生成的位图与Load的位图有区别吗?
- 关于在自已的程序中实现对控制台的完整封装
- 有什么vc的经典教程吗?
- 我有一个文件读取程序,在VC中使用F5就调试不过去,而我直接运行就可以得到正确结果?
- 用MFC写的程序怎么对VC有这么大的依靠性呢
- 简单问题
- 如何在程式中得到某个计划任务执行结果?
- 请教高手们:这个警告是怎么产生的?LINK : warning LNK4089: all references to "ADVAPI32.dll" discarded by /OPT:REF
- 有谁正在用STL port 4.0的?
- 可以定义类的指针吗
- 如何设置注册表为只读 不能修改
-----------------------------------------------
MyCSDN 免费版 - http://community.csdn.net/Expert/TopicView1.asp?id=4608614
InsertItem(index,...);
index++
}
把Item添好,然后再用另一个while循环调用SetItemText(index,);就可以。
CListCtrl Overview | Class Members | Hierarchy Chart | CListCtrl::DeleteItem | CListCtrl::DeleteAllItemsInserts an item into the list view control.
int InsertItem(
const LVITEM* pItem
);
int InsertItem(
int nItem,
LPCTSTR lpszItem
);
int InsertItem(
int nItem,
LPCTSTR lpszItem,
int nImage
);
Parameters
pItem
Pointer to an LVITEM structure that specifies the item's attributes, as described in the Platform SDK.
nItem
Index of the item to be inserted.
lpszItem
Address of a string containing the item's label, or LPSTR_TEXTCALLBACK if the item is a callback item. For information on callback items, see CListCtrl::GetCallbackMask.
nImage
Index of the item's image, or I_IMAGECALLBACK if the item is a callback item. For information on callback items, see CListCtrl::GetCallbackMask.
Return Value
The index of the new item if successful or -1 otherwise.
Example
// The pointer to my list view control.
extern CListCtrl* pmyListCtrl;CString strText;
int nColumnCount = pmyListCtrl->GetHeaderCtrl()->GetItemCount();// Insert 10 items in the list view control.
for (int i=0;i < 10;i++)
{
strText.Format(TEXT("item %d"), i); // Insert the item, select every other item.
pmyListCtrl->InsertItem(
LVIF_TEXT|LVIF_STATE, i, strText,
(i%2)==0 ? LVIS_SELECTED : 0, LVIS_SELECTED,
0, 0); // Initialize the text of the subitems.
for (int j=1;j < nColumnCount;j++)
{
strText.Format(TEXT("sub-item %d %d"), i, j);
pmyListCtrl->SetItemText(i, j, strText);
}
}
(以下签名由MyCSDN回复工具生成)
-----------------------------------------------
MyCSDN 免费版 - http://community.csdn.net/Expert/TopicView1.asp?id=4608614
The index of the new item if successful or -1 otherwise.(以下签名由MyCSDN回复工具生成)
-----------------------------------------------
MyCSDN 免费版 - http://community.csdn.net/Expert/TopicView1.asp?id=4608614