void dataGridView1_DragDrop(object sender, DragEventArgs e)
{
object data = e.Data.GetData(typeof(string));
MessageBox.Show(e.X + " " + e.Y + " " + dataGridView1.HitTest(e.X, e.Y).RowIndex.ToString());
if (dataGridView1.HitTest(e.X, e.Y).Type == DataGridViewHitTestType.Cell)
{
MessageBox.Show("!");
}
}
如果我尝试使用上述测试代码将项目拖动到datagridview中,我可以正确地从
data.ToString()
获取数据,但我无法定位行或单元格。
RowIndex.ToString()
返回"-1",我的if语句返回false,因此永远不会进入if代码块。我的代码有什么问题?