0
我有持有我想要显示的字符串,该项目的ID类。如何显示的对象,其在列表框的的ToString?
ref class ListBoxItem {
private:
int id;
String^name;
public:
ListBoxItem(int id, const char * name) { this->id = id; this->name = gcnew System::String(name); }
virtual String^ToString() new { return name; }
};
而且我每个项目添加到列表框是这样的:
for(list<string>::iterator i = listItems.begin(); i != listItems.end(); i++)
listBoxItems->Items->Add(gcnew ListBoxItem(2, (*i).c_str()));
这将产生正确数量项目的ListBox
,但所有的项目被称为“ListBoxItem的”。
取而代之,我想让ListBox
显示在ListBoxItem
上调用ToString
方法时产生的字符串。
改变'new'到'override'工作,谢谢! – samwell 2013-03-28 00:51:09