zoukankan      html  css  js  c++  java
  • 关于C# 将DataGridView数据拖动到picturebox代码示例

    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);
    }
  • 相关阅读:
    tf.get_variable
    tf.Variable
    tf.placeholder
    conda命令详解
    linux查看程序运行时占用的内存
    ubuntu安装openssh-server
    sed命令
    二分查找
    vue简单使用
    斐波那契数列求解
  • 原文地址:https://www.cnblogs.com/yannis/p/2059023.html
Copyright © 2011-2022 走看看