Stack Exchange
Can't insert a item of list control
I'm trying to insert a item of list control when an add button is clicked. 
But an add button is clicked, it does not insert a item. 
also I changed View property of list control from icon to report.
Does following code have a problem? 
BOOL CMFCApplication7Dlg::OnInitDialog()
{
    CDialogEx::OnInitDialog();


    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000);

    CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
        BOOL bNameValid;
        CString strAboutMenu;
        bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
        ASSERT(bNameValid);
        if (!strAboutMenu.IsEmpty())
        {
            pSysMenu->AppendMenu(MF_SEPARATOR);
            pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
        }
    }


    SetIcon(m_hIcon, TRUE);         
    SetIcon(m_hIcon, FALSE);        


    // Here is insert columns.

    TCHAR *szText[2] = { _T("NAME"), _T("E-MAIL") };
    int nWid[2] = { 65, 180 };

    LV_COLUMN lCol;

    lCol.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
    lCol.fmt = LVCFMT_LEFT;

    for (int i = 0; i < 2;i++)
    {
        lCol.pszText = szText[i];
        lCol.iSubItem = i;
        lCol.cx = nWid[i];
        m_ListC.InsertColumn(i, &lCol);
    }

    return TRUE; 
}


// Here is insert item code. 
void CMFCApplication7Dlg::OnBnClickedButtAdd()
{

    TCHAR szText[50] = _T("");
    int nIndex = 0;

    UpdateData(TRUE);

    LVITEM litem;

    litem.mask = LVIF_TEXT;
    litem.iItem = nIndex;

    litem.iSubItem = 0;
    swprintf_s(szText, sizeof(szText), _T("%s"), m_strName);
    litem.pszText = (LPWSTR)szText;

    m_ListC.InsertItem(&litem);

    litem.iSubItem = 1;
    swprintf_s(szText, sizeof(szText), _T("%s"), m_strMail);
    litem.pszText = (LPWSTR)szText;
    m_ListC.SetItem(&litem);

    m_strName = _T("");
    m_strMail = _T("");

    nIndex++;
    UpdateData(FALSE);
}


You set information LVITEM that is not covered by the mask. Also the iSubItem member is not used in report mode when you insert a normal column.
User the member functions of the m_listC InsertColumn, InsertItem and SetItemText instead of the struct Version. It is less error prone.
Tipp: Use ASSERT/VERIFY to check if the things you are doing work... You have no error checking in your code.
