MFRASER wrote:
How can I tell what object type is dropped onto my control? Here is a
snippet of code.
private void lvwTasks_DragDrop(object sender,
System.Windows.Forms.DragEventArgs e)
{
//I want to know if e.Data is of type MyClass1 or MyClass2
Core.MyClass1 aTask = new MyClass1 ();
aTask = (Core.VariableMapping.MapXMLTask)e.Data.GetData(aT ask.GetType());
Core.MyClass2 aTask2 = new MyClass2 ();
aTask2 = (Core.VariableMapping.MapXMLTask)e.Data.GetData(aT ask2 .GetType());
}
Hi,
You check for null after the e.Data.GetData(). If it is null, the
dropped item is not of that type.
Like:
private void tabPage1_DragDrop(object sender,
System.Windows.Forms.DragEventArgs e)
{
Panel pnl =e.Data.GetData(typeof(Panel)) as Panel;
if(pnl == null)
{
//Dropped item is not a panel
}
else
{
//Dropped item is a panel
//Do appropriate action
//Return
}
PictureBox picBox =e.Data.GetData(typeof(PictureBox)) as PictureBox;
if(picBox == null)
{
//Dropped item is not a picture box
//Do appropriate action here
}
}
HTH,
APG