In WIN32 API
Code:
HWND hWnd;//of he listview ctrl
if(ListView_GetItemCount(hWnd)!=0)
{
//CleanUp the old Data
ListView_DeleteAllItems(hWnd);
while(ListView_DeleteColumn(hWnd,0)>0);// always delete only the first column over and over
ListView_SetItemCount(hWnd,0);
}
//Find the column width
GetClientRect(hWnd,&ClientRect);
iWidth=((ClientRect.right - ClientRect.left)-15)/NUM_COL;//15 for scroll bar
for(i=0;i<NUM_COL;i++)
{
LVColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT ;
LVColumn.fmt = LVCFMT_LEFT;
LVColumn.cx=iWidth;
LVColumn.pszText = "Column Title";
LVColumn.cchTextMax = lstrlen("Column Title");
LVColumn.iSubItem = 0;
LVColumn.iImage = 0;
LVColumn.iOrder = 0;
ListView_InsertColumn(hWnd,i,&LVColumn);
}
//to insert the items
LV_ITEM pItem;
sprintf(sDescription,"Item text");
pItem.mask=LVIF_TEXT | LVIF_PARAM;
pItem.iItem=Row;
pItem.iSubItem=Column;
pItem.state=0;
pItem.stateMask=0;
pItem.pszText=sDescription;
pItem.cchTextMax=STRING;//STRING = 64
pItem.iImage=0;
pItem.lParam=Row;
if(Column>=1) //Column is zero based
ListView_SetItemText(hWnd, Row, Column, sDescription);
else
ListView_InsertItem(hWnd, &pItem);