I try put the folder name in textbox so i’m used this code:
private: System::Void textBox1_DragEnter(System::Object^ sender, System::Windows::Forms::DragEventArgs^ e) {
if (e->Data->GetDataPresent(DataFormats::FileDrop))
{
e->Effect = DragDropEffects::Copy;
}
}
private: System::Void textBox1_DragDrop(System::Object^ sender, System::Windows::Forms::DragEventArgs^ e) {
if (e->Data->GetDataPresent(DataFormats::FileDrop))
{
textBox1->Text = Convert::ToString(e->Data->GetData(DataFormats::FileDrop));
}
}
It’s working (0 errors) but when i put folder into textbox, textbox show me not path but: System.String[]
I’m using: C++, .NET, Visual Studio 2010
Any ideas?
Is returning a
string[](an array of strings), not a singlestring. When you try to convert this to string usingConvert::ToString, it just uses the defaultObject.ToString()behavior of showing the type name. What else would you expect it to do? There is no default notion of aggregating an array of strings into a single one.You should use the object returned by
GetData(), and convert it to a string yourself. If you expect a single item, test for that, grab the first item, and you have your string.If you want to support many items, you can use
string.Join()for example and specify a delimiter.You should use this to get access to the dropped files data:
From there you can decide how to convert
itemsto a string.