日期:2014-05-18  浏览次数:21104 次

求救~DragEvent!!
我在datagrid1中,选中一行,进行拖放。在它的MouseMove()事件里调用DoDragDrop(),如果把它拖到datagrid2中,那么我在datagrid2的DragDrop()可以执行我的代码,一切正常。如果鼠标一直都在datagrid1里,好像一直处于拖放的状态,重新选择不能选中行,这个时候datagrid的MouseDown(),MouseUp()事件都不能触发,而且也不能执行DragDrop(),我想知道怎么才能把拖放状态取消掉。因为如果用户本来想拖把一行从datagrid1拖到datagrid2中,并且已经开始拖了,但是突然发现选错了一行,想换行,结果就不能换行了,因为不能选中。把我的代码贴出来给大家看看。


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OracleClient;
namespace ICYOS
{
  public partial class Form1 : Form
  {
  public Form1()
  {
  InitializeComponent();
  }
  Point _ptStartDrag;
  int _dragRow;

  DataSet dsc1Dbg2=new DataSet();
  OracleDataAdapter c1dgbAdp=new OracleDataAdapter();

   
  private void Form1_Load(object sender, EventArgs e)
  {
  string selectStr = "select * from kf_clientinfo";
  DataSet myDs = DBControl.GetData(selectStr);//执行sql
  c1TrueDBGrid1.DataSource = myDs.Tables[0];
   

  selectStr = "select * from kf_clientinfo1";
  DBControl.updatedata(c1dgbAdp, selectStr, dsc1Dbg2);)//执行sql
  c1TrueDBGrid2.DataSource = dsc1Dbg2.Tables[0];
  }

  private void c1TrueDBGrid1_MouseDown(object sender, MouseEventArgs e)
  {
  int row, col;
  this._ptStartDrag = Point.Empty;
  this._dragRow = -1;
  if (this.c1TrueDBGrid1.CellContaining(e.X, e.Y, out row, out col))
  {
  // Save the starting point of the drag operation.
  this._ptStartDrag = new Point(e.X, e.Y);
  this._dragRow = row;
  }


  }

  private void c1TrueDBGrid1_MouseMove(object sender, MouseEventArgs e)
  {

  // If we don't have an empty start drag point, then the drag has been initiated.
  if (!this._ptStartDrag.IsEmpty)
  {
  // Create a rectangle that bounds the start of the drag operation by 2 pixels.
  Rectangle r = new Rectangle(this._ptStartDrag, Size.Empty);
  r.Inflate(2, 2);

  // If we've moved more than 2 pixels, start the drag operation.
  if (!r.Contains(e.X, e.Y))
  {
   
  this.c1TrueDBGrid1.Row = this._dragRow;
  this.c1TrueDBGrid1.MarqueeStyle = C1.Win.C1TrueDBGrid.MarqueeEnum.HighlightRow;
  this.c1TrueDBGrid1.DoDragDrop(this._dragRow, DragDropEffects.Copy);
  c1TrueDBGrid1.Row = 0;
  }
  }

  }
  private void c1TrueDBGrid2_DragDrop(object sender, DragEventArgs e)
  {
  try
  {
  int row = (int)e.Data.GetData(typeof(int));

  // Use the grid's indexer to get some data.
  string codeclient = this.c1TrueDBGrid1[row, "codeclient"].ToString();


  // Add a new row to the data set for the bottom grid.
  DataRowView drv = dsc1Dbg2.Table