winforms 为什么这个托管阵列初始化是错误的?

txu3uszq  于 2023-04-07  发布在  其他
关注(0)|答案(1)|浏览(110)

我想声明一个托管数组,因为我需要在ListView上进行搜索,但是这个声明是错误的,我得到了这些错误:

array<ListViewItem^, 128> searchedItems = gcnew array<ListViewItem^>;

E0070   incomplete type is not allowed
E0079   expected a type specifier

我需要它从这里工作,这是一个按钮单击事件从主窗体:

private: System::Void button1_Click_1(System::Object^ sender, System::EventArgs^ e) {
    String^ searchString = tbDenominazione->Text;
    array<ListViewItem^>^ itemsSearched = gcnew array<ListViewItem^>^(listViewMain->Items->Count);
    int i = 0;
    int matches = 0;
    for (; i < listViewMain->Items->Count; i++) {
        ListViewItem^ currentItem = listViewMain->Items[i];
//      String^ currentItemText = currentItem->Text;

//      cout << msclr::interop::marshal_as<std::string>(currentItem->SubItems[1]->ToString());      
        
        if (currentItem->SubItems[1]->Text->Contains(searchString)) {
            matches++;
        } 
    }
    cout << "Corrispondenze trovate: " << matches << endl;
}
sf6xfgos

sf6xfgos1#

我解决了指定这个

cli::array<ListViewItem^, 128> searchedItems = gcnew cli::array<ListViewItem^>;

相关问题