请问怎么在listcontrol控件中指定的某行某列插入一项数据。

解决方案 »

  1.   

    m_listctrl.InsertItem(i,"");//插入第i行
    m_listctrl.SetItemText(i,n,"text");//设置第i行的第n列内容为text
      

  2.   

    m_list.InsertColumn( 0, "ID", LVCFMT_LEFT, 40 ); 
    m_list.InsertColumn( 1, "NAME", LVCFMT_LEFT, 50 ); 
    m_list.InsertColumn( 2, "SEX", LVCFMT_LEFT, 70 );     
    m_list.InsertColumn( 3, "TEL", LVCFMT_LEFT, 90);  CString strtemp;
    for(int i=0; i < 2; i++)
    {
    strtemp.Format("%d", i+1);
    int nRow = m_list.InsertItem(i, strtemp);
    strtemp.Format("ID%d", i+1);
    m_list.SetItemText(nRow, 1, strtemp);
    strtemp.Format("NAME%d", i+1);
    m_list.SetItemText(nRow, 2, strtemp);
    strtemp.Format("address%d", i+1);
    m_list.SetItemText(nRow, 3, strtemp);
    }
      

  3.   

    m_listctrl.DeleteColumn(0);
    m_listctrl.DeleteColumn(1);
    m_listctrl.DeleteColumn(2);
    m_listctrl.DeleteColumn(3);
    m_listctrl.DeleteColumn(4);
    m_listctrl.DeleteColumn(5);
    m_listctrl.DeleteColumn(6);
    m_listctrl.DeleteColumn(7); m_listctrl.InsertColumn(0, "index", LVCFMT_LEFT, 100, 0);
    m_listctrl.InsertColumn(1, "accountnum", LVCFMT_LEFT, 100, 1);
    m_listctrl.InsertColumn(2, "channelname", LVCFMT_LEFT, 100, 2);
    m_listctrl.InsertColumn(3, "year", LVCFMT_LEFT, 50, 3);
    m_listctrl.InsertColumn(4, "month", LVCFMT_LEFT, 50, 4);
    m_listctrl.InsertColumn(5, "day", LVCFMT_LEFT, 50, 5);
    m_listctrl.InsertColumn(6, "hour", LVCFMT_LEFT, 50, 6);
    m_listctrl.InsertColumn(7, "minute", LVCFMT_LEFT, 50, 7); m_pSet->MoveFirst();
    for(long i=0; !m_pSet->IsEOF(); i++)
    {
    m_listctrl.InsertItem(i, m_pSet->m_index);
    m_listctrl.SetItemText(i, 1, m_pSet->m_account);
    m_listctrl.SetItemText(i, 2, m_pSet->m_channel);
    m_listctrl.SetItemText(i, 3, m_pSet->m_year);
    m_listctrl.SetItemText(i, 4, m_pSet->m_month);
    m_listctrl.SetItemText(i, 5, m_pSet->m_day);
    m_listctrl.SetItemText(i, 6, m_pSet->m_hour);
    m_listctrl.SetItemText(i, 7, m_pSet->m_minute); m_pSet->MoveNext();
    }