【发布时间】:2019-11-21 23:08:08
【问题描述】:
我正在用 c++ 和 CLR 在 Visual Studio 中编写一个 Windows 窗体应用程序。 现在,我遇到了以下问题:
我读入一个文件并将所有重要信息保存在一个向量中。
第二步,我将所有项目转换为 CLR 数组并将此数组设置为 DataSource。
array<System::String^>^ PREDEFINED = gcnew array <System::String^>(OP->CIS_Values[OP->selectedCIS]->PREDEFINED_order.size());
for (int i = 0; i < OP->CIS_Values[OP->selectedCIS]->PREDEFINED_order.size(); i++) {
PREDEFINED[i] = msclr::interop::marshal_as<System::String^>(OP->CIS_Values[OP->selectedCIS]->PREDEFINED_order[i]);
}
this->comboBox_header_predefinedtypes->DataSource = PREDEFINED;
this->comboBox_header_predefinedtypes->SelectedIndex = -1;
delete PREDEFINED;
设置 DataSource 后,必须可以将其删除。在 C# 中,我可以使用
comboBox.DataSource = null;
但是它在 C++ 中是如何工作的呢?
我尝试了以下几种情况:
comboBox_header_predefinedtypes->DataSource = NULL;
comboBox_header_predefinedtypes->DataSource = 0;
comboBox_header_predefinedtypes->DataSource = -1;
comboBox_header_predefinedtypes->DataBindings->Clear();
comboBox_header_predefinedtypes->Items->Clear();
我在 DataSource 之前和之后使用 DataBindings 进行了尝试,但我总是得到相同的异常:
System.ArgumentException:“复杂的 DataBinding 接受 IList 或 IListSource 作为数据源”
我该如何解决这个问题?
谢谢帮助。
【问题讨论】:
标签: c++ visual-studio clr windows-forms-designer