我在 CMFCPropertyGridCtrl 中插入文本时遇到问题。基本上,我使用以下代码插入值:
void GridBuilder::buildGrid() {
int cycles = 0, buisnessRules = 0;
for(vector<cycle *>::iterator it = this->listCycle.begin(); it!= this->listCycle.end(); ++it) {
buisnessRules = 0;
cycles++;
if(!this->mFilter->assertCycleConstraints((*it)->idthread, (*it)->dataStart, (*it)->dateStop, (*it)->name.c_str(), cycles)) {
continue;
}
CString text;
text.Format(_T("cycle : %S"), (*it)->name.c_str());
CMFCPropertyGridProperty* parent = new CMFCPropertyGridProperty(text);
mGrid->AddProperty(parent);
time_t timestampBegin = (*it)->dataStart / 1000;
char bufferBegin[256];
strftime(bufferBegin, sizeof(bufferBegin), "%A %d %B %Y - %X", localtime(×tampBegin));
time_t timestampEnd = (*it)->dateStop / 1000;
char bufferEnd[256];
strftime(bufferEnd, sizeof(bufferEnd), "%A %d %B %Y - %X", localtime(×tampBegin));
text.Format(_T("%d"), (*it)->idthread); parent->AddSubItem(new CMFCPropertyGridProperty(_T("Thread Id"), text));
text.Format(_T("%S"), (*it)->name.c_str()); parent->AddSubItem(new CMFCPropertyGridProperty(_T("Name"), text));
text.Format(_T("%S:%d"), bufferBegin, (*it)->dataStart % 1000); parent->AddSubItem(new CMFCPropertyGridProperty(_T("DateStart"), text));
text.Format(_T("%S:%d"), bufferEnd, (*it)->dateStop % 1000); parent->AddSubItem(new CMFCPropertyGridProperty(_T("DateStop"), text));
parent->Expand(FALSE);
for(vector<br *>::iterator itBr = (*it)->listBr.begin(); itBr!=(*it)->listBr.end(); ++itBr) {
buisnessRules++;
if(!this->mFilter->assertBuisnessRuleConstraints((*itBr)->dateStart, (*itBr)->dateStop, (*itBr)->name.c_str(), buisnessRules)) {
continue;
}
UINT64 executionTime = (*itBr)->dateStop - (*itBr)->dateStart;
CString text;
text.Format(_T("%S (%d \u00B5s)"), (*itBr)->name.c_str(), executionTime);
CMFCPropertyGridProperty* buisnessRule = new CMFCPropertyGridProperty(text);
parent->AddSubItem(buisnessRule);
text.Format(_T("%S"), (*itBr)->name.c_str()); buisnessRule->AddSubItem(new CMFCPropertyGridProperty(_T("Name"), text));
text.Format(_T("%d \u00B5s"), executionTime); buisnessRule->AddSubItem(new CMFCPropertyGridProperty(_T("Execution time"), text));
buisnessRule->Expand(FALSE);
}
}
}
这可以正常工作并按我想要的方式显示所有内容。但是,我的向量通常非常大(超过 8 000 个元素),这需要大量时间来渲染......
我怀疑 CMFCPropertyGridCtrl 每次插入一个新元素时都会重绘整个树,这需要相当长的时间......
我的问题如下:如何在不重绘整个树的情况下在 CMFCPropertyGridCtrl 中添加文本?或者我该如何优化这段代码?谢谢 !