Click to See Complete Forum and Search --> : Open document with CListView


Hanying Chen
May 4th, 1999, 10:35 PM
Hi, everyone,

I make a doc-view program using CListView. As sample from MSDN, I initialize the columns of list in function OnInitialUpdate():
void CConsoleView::OnInitialUpdate()
{
CListView::OnInitialUpdate();

int i;
CListCtrl& ListCtrl = GetListCtrl();
LV_COLUMN lvc;
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT;
for(i = 0; i < NUM_COLUMNS; i++)
{
lvc.iSubItem = i;
lvc.pszText = _gszColumnLabel[i];
lvc.cx = _gnColumnWidth[i];
lvc.fmt = _gnColumnFmt[i];
ListCtrl.InsertColumn(i, &lvc);
}
}

And then I open documents. To my suprise, the view add all columns again. I read the help and find that OnInitialUpdate is called each time I open a new document. Then my question comes: how can I avoid over-add columns. I think one solution is adding a flag to indicate. But I also think it is not the correct way.

Secondly, in ClistView, I override OnDraw to show my document as:
void CConsoleView::OnDraw(CDC* pDC)
{
CConsoleDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

// TODO: add draw code for native data here
int index = pDoc->m_PacketArray.GetSize();
CListCtrl& ListCtrl = GetListCtrl();
while(index--)
pDoc->m_PacketArray.GetAt(index)->Draw(ListCtrl);
}

But this function never be called. I don't know why and how to solve it.

Thanks for your help on such a simple question

your sincerely,
Hanying Chen