关键代码如下 :
vector<CLinkerInfo>::size_type iLen = vecInfo.size();
for(unsigned int i = 0; i < iLen; ++i) {
theCtrl.InsertItem(i, _T(""));
//theCtrl.SetItemData(i, atoi(vecInfo[i].getAttribute("ID").c_str()));
//theCtrl.SetItemData(i, 0); string strAttribute;
for(unsigned int j = 0; j < iHeaderCount; ++j) {
strAttribute = vecInfo[i].getAttribute(vecStrHeaderInfo[j]);
if(!strAttribute.empty()) {
theCtrl.SetItemText(i, j, CA2W(strAttribute.c_str()));
TRACE("%d:%d is %s - %s \n",i, j, vecStrHeaderInfo[j].c_str(), strAttribute.c_str());
} }
}
TRACE的输出如下 :0:0 is 姓名 - wxm
0:1 is 称谓 - 蜗牛
0:2 is Email - [email protected]
0:3 is 手机 - 135
1:0 is 姓名 - snail
2:0 is 姓名 - hugo
从TRACE来看输出是正确的,但是程序本身只能显示第0列的内容(也就是TRACE中X:0的内容)
不知道大家是否遇到过这种问题?
vector<CLinkerInfo>::size_type iLen = vecInfo.size();
for(unsigned int i = 0; i < iLen; ++i) {
theCtrl.InsertItem(i, _T(""));
//theCtrl.SetItemData(i, atoi(vecInfo[i].getAttribute("ID").c_str()));
//theCtrl.SetItemData(i, 0); string strAttribute;
for(unsigned int j = 0; j < iHeaderCount; ++j) {
strAttribute = vecInfo[i].getAttribute(vecStrHeaderInfo[j]);
if(!strAttribute.empty()) {
theCtrl.SetItemText(i, j, CA2W(strAttribute.c_str()));
TRACE("%d:%d is %s - %s \n",i, j, vecStrHeaderInfo[j].c_str(), strAttribute.c_str());
} }
}
TRACE的输出如下 :0:0 is 姓名 - wxm
0:1 is 称谓 - 蜗牛
0:2 is Email - [email protected]
0:3 is 手机 - 135
1:0 is 姓名 - snail
2:0 is 姓名 - hugo
从TRACE来看输出是正确的,但是程序本身只能显示第0列的内容(也就是TRACE中X:0的内容)
不知道大家是否遇到过这种问题?
正确的输出应该是在第二行的第3列显示一个邮件地址。
但是截图上的第二行的第三列是空白的。目前的状况是TRACE输出表明代码是正确的,
但是listview的输出仅第1列有输出,
然而如果我再插入数据,刷新后,旧的数据就可以正确的输出。(新插入的数据除了第1列外没有显示)
难道CSDN的图片嵌入功能只能是网页链接地址吗?
theCtrl.SetItemText(i, j, CA2W(strAttribute.c_str()));
TRACE("%d:%d is %s - %s \n",i, j, vecStrHeaderInfo[j].c_str(), strAttribute.c_str()); 最诡异的在上面的代码中,
我的TRACE语句能够正常的显示我需要显示的内容,规格如下 :
X:X is xxx - xxx但是listview只能显示出第0列的内容,
就是如下的内容 :
0:X is xxx - xxx图片如下图 :
0:1, 1:1, 1:3 都没有显示出来(但是明明已经使用过theCtrl.SetItemText(i, j, CA2W(strAttribute.c_str()));插入过它们的!)
改用A2T(具体代码如下 :)后,问题依然存在 : (
USES_CONVERSION;
vector<CLinkerInfo>::size_type iLen = vecInfo.size();
for(unsigned int i = 0; i < iLen; ++i) {
theCtrl.InsertItem(i, _T(""));
theCtrl.SetItemData(i, atoi(vecInfo[i].getAttribute(g_cstr_Att_ID).c_str()));
string strAttribute;
for(unsigned int j = 0; j < iHeaderCount; ++j) {
strAttribute = vecInfo[i].getAttribute(vecStrHeaderInfo[j]);
if(!strAttribute.empty()) {
theCtrl.SetItemText(i, j, A2T(strAttribute.c_str()));
TRACE("%d:%d is %s - %s \n",i, j, vecStrHeaderInfo[j].c_str(), strAttribute.c_str());
}
}
}
假如去掉CA2W,使用强制转换,则会出现乱码,并且bug依然存在。
代码如下 :
USES_CONVERSION;
vector<CLinkerInfo>::size_type iLen = vecInfo.size();
for(unsigned int i = 0; i < iLen; ++i) {
theCtrl.InsertItem(i, _T(""));
theCtrl.SetItemData(i, atoi(vecInfo[i].getAttribute(g_cstr_Att_ID).c_str()));
string strAttribute;
for(unsigned int j = 0; j < iHeaderCount; ++j) {
strAttribute = vecInfo[i].getAttribute(vecStrHeaderInfo[j]);
if(!strAttribute.empty()) {
//theCtrl.SetItemText(i, j, A2T(strAttribute.c_str()));
theCtrl.SetItemText(i, j, (LPCTSTR)strAttribute.c_str());
TRACE("%d:%d is %s - %s \n",i, j, vecStrHeaderInfo[j].c_str(), strAttribute.c_str());
}
}
}
工程是unicode编码,如果是编码问题,那为什么不出现乱码呢?