关于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); }
相关文章推荐
- c#DataGridView数据绑定示例——格式化单元格的内容(转)
- 关于VS2005中C#代码用F12转到定义时,总是显示从元数据的问题?
- C# 关于从数据库取数据,并显示在DataGridView中
- 关于C#代码用F12转到定义时,总是显示从元数据的解决方法
- Ajax 实现在WebForm中拖动控件并即时在服务端保存状态数据 (Asp.net 2.0)(示例代码下载)
- 关于C# Winform dataGridView显示时没有默认选中以及dataGridView添加DataTable中的数据
- 关于VS2005中C#代码用F12转到定义时,总是显示从元数据的问题题
- Ajax 实现在WebForm中拖动控件并即时在服务端保存状态数据 (Asp.net 2.0)(示例代码下载)
- C#判断数据类型的简单示例代码
- C#.NET示例读写xml所有节点的代码实现方法和读取xml节点的数据总结
- Ajax 实现在WebForm中拖动控件并即时在服务端保存状态数据 (Asp.net 2.0)(示例代码下载)
- 关于C#代码用F12转到定义时,总是显示从元数据的解决方法
- Python脚本调用C#代码数据交互示例(hello world)
- C#动态数据绘图graphic代码简单示例
- C# winform关于datagridview中的列的数据类型转换问题
- 关于C#中datagridview中的数据绑定
- C#中关于泛型方法和泛型委托的示例代码
- 转载:Ajax 实现在WebForm中拖动控件并即时在服务端保存状态数据 (Asp.net 2.0)(示例代码下载)
- C# DataGridView 代码实现选中一行数据
- 关于VS2005中C#代码用F12转到定义时,总是显示从元数据的问题