CListView Population is slow (populate with std::string and doubles)
Posted on 2009-04-23
I am creating an MFC application where one of my document views is a list view. The data I want to populate the list with is a time series, the header row being the name of the series, the first column being times, and the rest of the columns should be filled with data. In some sense this resembles the view in Excel.
My problem is that populating the listview is extremely slow. The code doing that part is:
CListCtrl& m_List = GetListCtrl();
CSeriesDoc *iDoc = GetDocument();
unsigned int nr = iDoc->iSeries.timelength();
unsigned int nc = iDoc->iSeries.serieslength();
for (unsigned int i=0; i<nr; i++)
lvItem.mask = LVIF_TEXT;
lvItem.iItem = i;
lvItem.iSubItem = 0;
iS << iDoc->iSeries.t(i);
lvItem.pszText = str2lpstr(iS.str());
nItem = m_List.InsertItem(&lvItem);
for (unsigned int j=0; j<nc; j++)
double d_ = iDoc->iSeries(i,j);
std::string s_ = boost::lexical_cast<std::string,double>(d_);
m_List.SetItemText(nItem, j+1, str2lpstr(s_));
The iSeries is my time series object, its member function t simply returns the time (boost posix_time) for the current row, str2lpstr is my own function converting a std::string to a lpstr and the boost::lexical_cast is my own clumsy way of converting a double to a std::string.
I guess all this stupid conversion is what slows down my application. But it could of course also be the way I use ListView in general. I hope some of you have an idea or two that would help me out.