您的位置:首页 > 编程语言 > C#

关于C# 将DataGridView数据拖动到picturebox代码示例

2011-05-26 17:22 676 查看
this.PictureBoxNodeBackImage.AllowDrop = true; //这个也要加上


//最后我们判断完成后怎样向PictureBox中添加数据,并从datagridview中删除选中数据所在的行,我们在PictureBox的DragDrop事件中执行操作
private void PictureBoxNodeBackImage_DragDrop(object sender, DragEventArgs e)
{               Point pos = new Point(e.X, e.Y);   //拖動數據后 所記錄的坐標
pos = this.PictureBoxNodeBackImage.PointToClient(pos);
int index = -1;
if (e.Data.GetDataPresent(typeof(int)))
{
index = (int)e.Data.GetData(typeof(int));
}
if (index > -1)
MessageBox.Show(DataGridViewleizhi.Rows[index].Cells["Id"].Value.ToString());
}


//再次确定当数据拖动到PictureBox上方时,判断数据格式以及目标对象,和拖动方式.我们在PictureBox的DragEnter 事件中进行判断
private void PictureBoxNodeBackImage_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(int)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}


private void DataGridViewleizhi_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
DataGridViewleizhi.DoDragDrop(e.RowIndex, DragDropEffects.Copy);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐