Drag and Drop dropData is null
Good day everyone.
I'm writing a revit API that can
1. list all .rfa files' name from another computer,
2. single click file name to download to a custom directory at my local computer and
3. drag file name to place the component into revit.
I've finished the first two but when I drag and drop the file name to revit, a prompt shows up and says
"Value cannot be null. Parameter name: dropData".
I'm using Visual Studio 2019, winForm, .NET Framework v4.5.2, revit 2017 dll and revit 2017.
I copy the code from here , using these codes.
public class LoadedFamilyDropHandler : IDropHandler
{
public void Execute(UIDocument document, object data)
{
ElementId familySymbolId = (ElementId)data;
FamilySymbol symbol = document.Document.GetElement(familySymbolId) as FamilySymbol;
if(symbol != null)
{
document.PromptForFamilyInstancePlacement(symbol);
}
}
}
private void listView1_MouseMove(object sender, MouseEventArgs e)
{
if(System.Windows.Forms.Control.MouseButtons == MouseButtons.Left)
{
if(System.Windows.Forms.Control.MouseButtons == MouseButtons.Left)
{
ListViewItem selectedItem = this.listView1.SelectedItems.Cast<ListViewItem>().FirstOrDefault<ListViewItem>();
if(selectedItem != null)
{
LoadedFamilyDropHandler myhandler = new LoadedFamilyDropHandler();
UIApplication.DoDragDrop(selectedItem.Tag, myhandler);
}
}
}
}
My custom directory path is D:\DownloadedFromVault\ which contains all .rfa files downloaded from another computer.
This is the code when I click the file name and download it from the list view.
client.DownloadFile(server + path + "\\" + listView1.SelectedItems[0].Text, localFilePath + path + "\\" + listView1.SelectedItems[0].Text);
I guess that API cannot find the file because I store them in another directory ,or maybe the file name doesn't connect to the file downloaded.
I don't know how exactly drag and drop functions. Hope someone can help me with this and give me some insights.