单文档,在CListView的OnInitialUpdate中插入ITEM 不显示?
gbcin 2012-08-22 01:46:46 昨天把这儿问题发到微软的网站上,结果无人回答,555~~~~
http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/56ef84ae-74ac-429c-a96e-90589a481f55
这个问题困扰我几天了。
求教下国内的各位大虾。。。
我有个单文档的程序。
用CFixedSplitter::CreateStatic and CFixedSplitter::CreateView把试图分割成了3份。
其中一份试图,我用的是派生自CListView的自定义类“CViewLog”。
现在的问题是我在CViewLog::OnInitialUpdate使用下面的代码,给CListCtrl添加item,程序运行后item不显示。
然后我建了个基于对话框的工程,放了个list control,在按钮里面用下面的代码,就可以显示item。
这个listview是我用来显示程序操作日志的,最终是希望在document类里面给listview添加item。
多谢。。。
There's a SDI application.
I split it into 3 views with CFixedSplitter::CreateStatic and CFixedSplitter::CreateView in OnCreateClient of CMainFrame.
One of these 3 views would show logs of this application.
Thus, I defined a Class named "CViewLog" with "CListView" as its parent.
In CViewLog::OnInitialUpdate, I put following code.
The problem of this code is that no item will be shown after launching application.
But the test code(See my comment) indicates the item is inserted and set successfully.
Then I created a dialog based project in VS where following code works well.
I did a search online and found this thread with almost the same issue:
http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/7dcab41b-d176-401e-be06-6a5d57973940
I tried the solution but still not working.
What I want is to insert item to CViewLog's CListCtrl from the document class.
Appreciate your help. Thanks.
/*****************************************************************/
void CViewLog::OnInitialUpdate(void)
{
// create image list and add column header to listCtrl
DWORD lStyle = 0;
CString csTemp;
int nRow = 0;
m_ImList.Create(16,16,TRUE,2,1);
m_ImList.Add(AfxGetApp()->LoadIcon(IDI_ICON3));
m_ImList.Add(AfxGetApp()->LoadIcon(IDI_ICON4));
CListCtrl& cList = (CListCtrl&)GetListCtrl();
cList.SetImageList(&m_ImList, TVSIL_NORMAL);
lStyle = GetWindowLong(cList.m_hWnd, GWL_STYLE);
lStyle &= ~LVS_TYPEMASK;
lStyle |= LVS_REPORT;
SetWindowLong(cList.m_hWnd, GWL_STYLE, lStyle);
cList.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
cList.InsertColumn(0,"Date", LVCFMT_IMAGE| LVCFMT_LEFT,100,0);
cList.InsertColumn(1,"Time", LVCFMT_LEFT,100,0);
cList.InsertColumn(2,"Event", LVCFMT_LEFT,740,0);
cList.DeleteAllItems();
nRow = cList.InsertItem(0,"asdf");
cList.SetItem(nRow, 1, TVIF_TEXT, "1234", 0, 0, 0, 0);
cList.SetItem(nRow, 2, TVIF_TEXT, "1234", 0, 0, 0, 0);
//test code
nRow = cList.GetItemCount();
csTemp = cList.GetItemText(0,1);
CListView::OnInitialUpdate();
}