We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Restrict selection to single cell

Thread ID:

Created:

Updated:

Platform:

Replies:

6425 Aug 12,2003 01:29 PM Aug 12,2003 01:48 PM Windows Forms 1
loading
Tags: GridControl
Dave Erwin
Asked On August 12, 2003 01:29 PM

How can I prevent the selection of multiple cells when the mouse is dragged through a group of cells? What I would really like to do is have the drag move the cell without having to hover the cursor on the bottom edge of it to get the move cursor. The application is a production schedule, the contents of the cells are not going to be editted, just moved around within the grid. TIA, Dave Erwin

Administrator [Syncfusion]
Replied On August 12, 2003 01:48 PM

You can handle the grid.Model.SelectionsChanging event and set e.Cancel = true if e.Range is not empty and has more than 1 cell in it. But you may not need this. Below is some code that you can add to Syncfusion\Essential Suite\Grid\Samples\DataBound\GridDataBoundImageCell sample to enable dragging a picture in sample just by mousing down and dragging it (without moving the mouse to the edge of the selection). Maybe you can use something similar to start a drag of one of your cells without relying on the built-in D&D support that requires selecting cells and then starting drag from an edge.
//in formload, subscribe to the events
this.gridDataBoundGrid1.MouseDown += new MouseEventHandler(grid_MouseDown);
this.gridDataBoundGrid1.MouseMove += new MouseEventHandler(grid_MouseMove);
this.gridDataBoundGrid1.MouseUp += new MouseEventHandler(grid_MouseUp);

//the handlers
private Point mouseDownPoint = Point.Empty;
private int mouseDownRow = -1;
private int mouseDownCol = -1;

private void grid_MouseDown(object sender, MouseEventArgs e)
{
	Point pt = new Point(e.X, e.Y);
	int rowIndex, colIndex;
	if(this.gridDataBoundGrid1.PointToRowCol(pt, out rowIndex, out colIndex, -1))
	{
		//check for photo column mousedown
		if(this.gridDataBoundGrid1[0, colIndex].Text == "Photo"
			&& rowIndex > 0)
		{
			mouseDownPoint = new Point(e.X, e.Y);
			mouseDownRow = rowIndex;
			mouseDownCol = colIndex;
		}
		else
		{
			mouseDownPoint = Point.Empty;
			mouseDownRow = -1;
			mouseDownCol = -1;
		}
	}
}

private void grid_MouseMove(object sender, MouseEventArgs e)
{
	//check if dragging...
	if(mouseDownPoint != Point.Empty)
	{
		if(Math.Abs(mouseDownPoint.X - e.X)
			+ Math.Abs(mouseDownPoint.Y - e.Y) > 8)
		{
			//get the bitmap however???
			Byte[] pict = this.gridDataBoundGrid1[mouseDownRow, mouseDownCol].CellValue as Byte[];
			if(pict != null)
			{
				int PictOffSet = 78;
				MemoryStream buffer = new MemoryStream(pict, PictOffSet, pict.Length - PictOffSet);
				Bitmap image =   (Bitmap)Bitmap.FromStream(buffer, true);

				this.DoDragDrop(image, DragDropEffects.All);
			}
			mouseDownPoint = Point.Empty;
			mouseDownRow = -1;
			mouseDownCol = -1;
		}
	}
}

private void grid_MouseUp(object sender, MouseEventArgs e)
{
	mouseDownPoint = Point.Empty;
	mouseDownRow = -1;
	mouseDownCol = -1;
}

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;