初始化
TCHAR rgtsz[10][20] = {_T("进货时间"),_T("货物名"), _T("数量"), _T("单位"), _T("单件中的数量"), _T("单件中的单位"), _T("单价"), _T("含量"), _T("来源"), _T("类型")};
LV_COLUMN lvcolumn;
CRect rect;
m_licList.GetWindowRect(&rect);
for(int i=0;i<9;i++)
{
lvcolumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH | LVCF_ORDER;
lvcolumn.fmt = LVCFMT_LEFT;
lvcolumn.pszText = rgtsz[i];
lvcolumn.iSubItem = i;
lvcolumn.iOrder = i;
if(i==0)
{
lvcolumn.cx = rect.Width()*1/10 ;
}
else
{
lvcolumn.cx = rect.Width()*1/10;
}
m_licList.InsertColumn(i, &lvcolumn);
}
m_licList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_TRACKSELECT|LVS_EX_UNDERLINEHOT|LVS_EX_GRIDLINES);
添加数据
CString str;
m_licList.DeleteAllItems() ;
INT nRow = 0 ;
for ( INT nIndex = 0 ; nIndex < m_aySinfo.GetSize() ; nIndex ++ )
{
nRow = m_licList.InsertItem( 0, m_aySinfo.ElementAt( nIndex ).strTime );//插入行
m_licList.SetItemText( nRow, 1, m_aySinfo.ElementAt( nIndex ).strTypeName );
str.Format( "%f", m_aySinfo.ElementAt( nIndex ).fCount ) ;
m_licList.SetItemText( nRow, 2, str );//设置数据
m_licList.SetItemText( nRow, 3, m_aySinfo.ElementAt( nIndex ).strUnit );
str.Format( "%f", m_aySinfo.ElementAt( nIndex ).fOneWeight ) ;
m_licList.SetItemText( nRow, 4, str );
m_licList.SetItemText( nRow, 5, m_aySinfo.ElementAt( nIndex ).strOntWeightUnit );
str.Format( "%f", m_aySinfo.ElementAt( nIndex ).fPrice ) ;
m_licList.SetItemText( nRow, 6, str );
m_licList.SetItemText( nRow, 7, m_aySinfo.ElementAt( nIndex ).strmember );
m_licList.SetItemText( nRow, 8, m_aySinfo.ElementAt( nIndex ).strSource );
m_licList.SetItemText( nRow, 9, m_aySinfo.ElementAt( nIndex ).strType );
}