Larry Lard wrote:
jo*********@topscene.com wrote:
If I click down on a control on a form and then drag and release on a
datagridview, how can I tell which cell the release occured over?
When the drag is dropped, the DGV will receive a DragDrop event
containing the screen coordinates of the drop point. Convert these to
client coordinates with PointToClient, then use the HitTest method to
workout where the drop was. Sample code:
Private Sub DataGridView1_DragDrop(ByVal sender As Object, ByVal e
As System.Windows.Forms.DragEventArgs) Handles DataGridView1.DragDrop
One day I will learn to check which group I am posting to.
public Form1()
{
InitializeComponent();
dataGridView1.AllowDrop = true;
dataGridView1.DragEnter += new
DragEventHandler(dataGridView1_DragEnter);
dataGridView1.DragDrop += new
DragEventHandler(dataGridView1_DragDrop);
}
void dataGridView1_DragDrop(object sender, DragEventArgs e)
{
Point dropPointScreen = new Point(e.X, e.Y);
Point dropPointClient =
dataGridView1.PointToClient(dropPointScreen);
DataGridView.HitTestInfo hitTest =
dataGridView1.HitTest(dropPointClient.X,
dropPointClient.Y);
MessageBox.Show("Dropped on row " +
hitTest.RowIndex.ToString() +
", column " +
hitTest.ColumnIndex.ToString());
}
void dataGridView1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}
--
Larry Lard
Replies to group please
When starting a new topic, please mention which version of VB/C# you
are using