Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPF - Dragging multiple gridrows not working #1179

Closed
TomQv opened this issue Aug 18, 2018 · 3 comments
Closed

WPF - Dragging multiple gridrows not working #1179

TomQv opened this issue Aug 18, 2018 · 3 comments
Milestone

Comments

@TomQv
Copy link

TomQv commented Aug 18, 2018

  • Selecting multiple rows in a grid.
  • trying to start a drag-operation with left mouse button down on the selection
  • selection is cleared immediately, and dragging is initiated with just that single row where the mousedown was clicked.

Only WPF, on OSX this is working fine with multiple rows

Reproducible with Eto.Test "Drag and Drop"

@TomQv
Copy link
Author

TomQv commented Aug 18, 2018

The following hack added as a style is a workaround, if someone needs this:

Eto.Style.Add<Eto.Wpf.Forms.Controls.GridViewHandler>(null, handler =>
{
	Point p0= default (Point);
	object row = null;

	var swcgrid = (handler.Control as System.Windows.Controls.DataGrid);
	//swcgrid.AlternatingRowBackground = AlternateRowsColor;

	swcgrid.PreviewMouseDown += (object sender, System.Windows.Input.MouseButtonEventArgs e) =>
	{
	// avoid clearing the selection of multiple items, when starting to drag selected items
	// https://stackoverflow.com/questions/16894348/datagridview-multirow-select-clearing-on-left-mouse-button-drag-and-drop
		
	   row = null;
	   if (e.LeftButton == System.Windows.Input.MouseButtonState.Pressed &&
			swcgrid.SelectedItems.Count > 1)
		{
			//find item under mouse
			var p = e.GetPosition(swcgrid);
			row = handler.GetCellAt(new Eto.Drawing.PointF((float)p.X, (float)p.Y), out int c, out int r);
			if (swcgrid.SelectedItems.Contains(row))
			{
				swcgrid.Focus();
				p0 = e.GetPosition(swcgrid);
				// it is selected, so dont proceed with this event, otherwise WPF would deselect all, whoch would make dragging impossible
				e.Handled = true;
			}
		}
		else if (e.RightButton == System.Windows.Input.MouseButtonState.Pressed)
		{
			// make sure, grid gets focus on right mouse click, important for Popup-menu
			swcgrid.Focus();
		}
	};

	swcgrid.PreviewMouseUp += (object sender, System.Windows.Input.MouseButtonEventArgs e) =>
	{
		if (row != null)
		{
			// check if mouse up was at the same point like mousedown, meaning, there was no dragging
			var p1 = e.GetPosition(swcgrid);
			if (p0 == p1)
			{
				// clear selection and select the row we just clicked
				swcgrid.SelectedItem = row;
				e.Handled = true;
			}
		}
	};
});

@cwensley
Copy link
Member

Hey @TomQv, thanks for reporting the issue (and supplying a workaround, it is very helpful!).

@cwensley
Copy link
Member

Now fixed with #1505 and #1508

Thanks again for reporting this issue!

@cwensley cwensley modified the milestones: 2.x, 2.5 Nov 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants