glcjr

I'm trying to drag and drop a file onto a form and having the file open up in an editor...

private: System::Void toc_DragEnter(System::Object^ sender, System::Windows::Forms::DragEventArgs^ e) {

if (e->Data->GetDataPresent(DataFormats::FileDrop))

e->Effect = DragDropEffects::Copy;

else

e->Effect = DragDropEffects::None;

}

private: System::Void toc_DragDrop(System::Object^ sender, System::Windows::Forms::DragEventArgs^ e) {

String ^file = e->Data->GetData("FileNameW")->ToString();

editor ^ed = gcnew editor(true,HW, file);

ed->Show();

}

But what's making it to the Editor is: System.String[] instead of the filename.

I originally had e-Data->GetData(DataFormats::FileDrop)->ToString() in the dragdrop and it was sending the same thing. What am I doing wrong.

I just realized I need to change the Show to a ShowDialog... But I doubt that's the problem.




Re: Visual C++ Language Drag and Dropping a file

einaros

glcjr wrote:

But what's making it to the Editor is: System.String[] instead of the filename.

GetData(DataFormats::FileDrop), "FileName" and "FileNameW" all return string arrays, as multiple files (and hence multiple file names) may be dropped.

Try

array<String^>^ filenames = dynamic_cast<array<String^>^>(e->Data->GetData("FileName"));
// do whatever with filenames[0]






Re: Visual C++ Language Drag and Dropping a file

glcjr

Thank you einaros!