Click to See Complete Forum and Search --> : ??? File opening by dragging and dropping - confused


alekkh
November 7th, 2005, 09:52 PM
I'm trying to open a file in Windows Forms by DragDrop, DrgEnter.

Everything works fine except I cannot seem to obtain the FileName from which to open the file: I always get "System.String[]" as the file destination...

Searching forums gave some results but nothing worked for me. Pleas help with just one string of code in C++!..

++++++
working example::::

public: System::Void Form1_DragDrop(System::Object^ sender, System::Windows::Forms::DragEventArgs^ e) {

textBox1-> Text = "OK";
}

++++++++
works nicely and inserts "OK"


but

non-working example:::::



public: System::Void Form1_DragDrop(System::Object^ sender, System::Windows::Forms::DragEventArgs^ e) {

this->textBox5 ->Text = Convert::ToString(e->Data->GetData(DataFormats::FileDrop, "FileName"));

}

inserts "System.String[]" instead of file name of the file that I dragged and dropped.


How to make it return i.e.
"C:\Programs... " instead??? Many thanks.

Marc G
November 8th, 2005, 03:03 AM
[ moved thread ]

darwen
November 8th, 2005, 04:22 AM
Firstly, you can drag and drop multiple files onto an application : this is why you get an array of strings in the drop.

Try this :


System::String ^aFiles[] = dynamic_cast<System::String ^[]>(e->Data->GetData(DataFormats::FileDrop)));
this->textBox5 ->Text = aFiles[0];


Darwen.

alekkh
November 8th, 2005, 12:17 PM
Firstly, you can drag and drop multiple files onto an application : this is why you get an array of strings in the drop.

Try this :


System::String ^aFiles[] = dynamic_cast<System::String ^[]>(e->Data->GetData(DataFormats::FileDrop)));
this->textBox5 ->Text = aFiles[0];


Darwen.



Thanks, I've tried that and compilers said:

: error C2728: 'System::String ^' : a native array cannot contain this managed type
Did you mean 'array<System::String ^>'?
: error C2440: 'initializing' : cannot convert from 'System::String ^' to 'System::String ^[]'
No user-defined-conversion operator available, or
There are no conversions to array types, although there are conversions to references or pointers to arrays
: error C2059: syntax error : ']'

darwen
November 8th, 2005, 04:00 PM
I'm not sure - I don't have VC++ 2005.

Try this :


System::String ^aFiles __gc [] = dynamic_cast<System::String ^ __gc []>(e->Data->GetData(DataFormats::FileDrop);
System::String ^myString = aFiles[0];


or this :


System::String ^[] aFiles = dynamic_cast<System::String ^[]>(e->Data->GetData(DataFormats::FileDrop);
System::String ^myString = aFiles[0];


or even :


System::Array ^aFiles = dynamic_cast<System::Array ^>(e->Data->GetData(DataFormats::FileDrop);
System::String ^myString = dynamic_cast<System::String ^>(aFiles[0]);


Darwen.

NoHero
November 8th, 2005, 04:10 PM
I'm not sure - I don't have VC++ 2005.

Try this :
or this :
or even :

Darwen.


array<System::String ^> ^aFiles = dynamic_cast<array<System::String^> >(e->Data->GetData(DataFormats::FileDrop));

Is correct...

alekkh
November 8th, 2005, 08:12 PM
Thanks guys, you are great! This one definitely required your input.

Does anyone understand why newer VS has to be so incompatible with older synthax!?..


Now, this doesn't work:

array<System::String ^> ^aFiles = dynamic_cast<array<System::String^> >(e->Data->GetData(DataFormats::FileDrop));



but this does :))))

array<System::String ^> ^aFiles = dynamic_cast<array<System::String^>^ >(e->Data->GetData(DataFormats::FileDrop));

NoHero
November 9th, 2005, 06:20 AM
Sorry a typo from my side...