private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
DataGridView.HitTestInfo info = dataGridView1.HitTest(e.X, e.Y);
if (info.RowIndex >= 0 && info.ColumnIndex >= 0)
{
string text = Convert.ToString(dataGridView1.Rows[info.RowIndex].Cells[info.ColumnIndex].Value);
if (text != null)
{
dataGridView1.DoDragDrop(text, DragDropEffects.Copy);
}
}
}
}
private void dataGridView1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
private void dataGridView1_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(System.String )))
{
DataGridView dgv = (DataGridView)sender;
Point p = dgv.PointToClient(new Point(e.X, e.Y));
DataGridView.HitTestInfo info= dgv.HitTest(p.X, p.Y);
if (info.RowIndex >= 0 && info.ColumnIndex >= 0)
{
dataGridView1[info.ColumnIndex,info.RowIndex].Value = e.Data.GetData(typeof(System.String));
dgv.CurrentCell = dataGridView1[info.ColumnIndex, info.RowIndex];
dgv.CurrentCell.Selected = true;
}
}
}
|