DragDrop files to C++ CLR application

Viewed 18

Visual Studio 2022, Windows CLR form with ListBox and listbox have AllowDrop=True.
Used events DragEnter and DragDrop:
private: System::Void listBox1_DragEnter(System::Object^  sender, System::Windows::Forms::DragEventArgs^  e) {
if (e->Data->GetDataPresent(DataFormats::FileDrop))
    e->Effect = DragDropEffects::Move;
else
    e->Effect = DragDropEffects::None;
}

(This working properly)

private: System::Void listBox1_DragDrop(System::Object^  sender, System::Windows::Forms::DragEventArgs^  e) {
    auto lst = e->Data->GetData(DataFormats::FileDrop, false);
    array< String^ >^ test = gcnew array< String^ >(5);

    listBox1->Items->Add(lst->GetType());
    listBox1->Items->Add(Convert::ToString(sizeof(lst)));
    listBox1->Items->Add(test->GetType());
    listBox1->Items->Add(Convert::ToString(sizeof(test)));

    test[2] = "bb";
    listBox1->Items->Add(test[2]);
    // listBox1->Items->Add(lst[2]); 
}

After drop 5 files, list contain:

System.String[]
8
System.String[]
8
bb

But if I enable line with lst[2], lst is underlined in red and try of compilation ends with errors E2242 and C3915.
Some hints?

1 Answers

The answer is known if anyone is interested: GetType looks the same, but type conversion helped.

array<String^>^ lst = (array<String^>^)e->Data->GetData(DataFormats::FileDrop, false);
for each(String ^ path in lst) listFiles2->Items->Add(path);
Related