1
votes

In my application, I create a modal dialog that contains a mfc List Control. When I don't initialize any columns or items in the List Control, the dialog shows without error. When I try to add a column to the List Control, I get the following Debug Assertion Failed message:

Debug Assertion Failed!

If it helps, the breakpoint is at

_AFXCMN_INLINE int CListCtrl::InsertColumn(int nCol, const LVCOLUMN* pColumn) { ASSERT(::IsWindow(m_hWnd)); return (int) ::SendMessage(m_hWnd, LVM_INSERTCOLUMN, nCol, (LPARAM)pColumn); }

I am trying to add the column headers with the following code in OnInitDialog():

BOOL EventL::OnInitDialog()
{
    m_ListEventLog.InsertColumn(0, _T("Description"), LVCFMT_LEFT, 250);  //Failure happens HERE
    //m_ListEventLog.InsertColumn(0, "Description", LVCFMT_LEFT, 200, 0); //I have also tried things such as this.
    return FALSE;
}

I add column headers to other CListControls in my application in this way, without problems. The modal dialog is called with the code:

void ListOption::OnBnClickedEventLog()
{
    EventL eventLog;
    eventLog.DoModal();
}
2

2 Answers

2
votes

Maybe you forgot to call the default function:

BOOL EventL::OnInitDialog()
{
    BOOL res = CDialog::OnInitDialog();
    m_ListEventLog.InsertColumn(0, _T("Description"), LVCFMT_LEFT, 250);  //Failure happens HERE
    //m_ListEventLog.InsertColumn(0, "Description", LVCFMT_LEFT, 200, 0); //I have also tried things such as this.
    return res; // or return FALSE;
}

That's why ASSERT(::IsWindow(m_hWnd)) fails, because m_hWnd of ListView control is not ready. m_hWnd of dialog would not be ready either.

0
votes

I had the same issue, until i added DDX_Control(pDX, IDC_LIST1, movies); to

    void MainDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_LIST1, movies);
}

movies - is name of the Listcontrol

CListCtrl movies;