I have a Winforms app written in C#.
On my form I have two DataGridViews
I have set up a drag and drop operation between the two DataGridViews so that dragging from dataContact sends the int ID across to dataContactBusiness.
However on the Drop I get an error 'object not set to an instance'
When I step through my code I can see that DragEventArgs e contains the ID in its Data, so I fail to see why I am getting the error message.
My code is as follows -
private void dataContact_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
DataGridViewRow row = dataContact.Rows[e.RowIndex];
int conID = (int)row.Cells["ID"].Value;
dataContact.DoDragDrop(conID, DragDropEffects.All);
}
private void dataContactBusiness_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}
private void dataContactBusiness_DragDrop(object sender, DragEventArgs e)
{
string data = e.Data.GetData(DataFormats.Text).ToString(); //...error occurs here
}

The data value of '5' is what I expected, so why the error?