C#实现拖拽

        private void dgvPbom_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            dgvPbom.DoDragDrop(e.ColumnIndex, DragDropEffects.Copy);
        }

        private void txtProjectCode_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(int)))
            {
                e.Effect = DragDropEffects.Copy;
            }
            else
                e.Effect = DragDropEffects.None;
        }

        private void txtProjectCode_DragDrop(object sender, DragEventArgs e)
        {
            int index = -1;
            if (e.Data.GetDataPresent(typeof(int)))
                index = (int)e.Data.GetData(typeof(int));
            if (index > -1)
                txtProjectCode.Text = dgvPbom.Columns[index].Name;
        }

你可能感兴趣的:(C#)