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. Image for the cookie policy date
close icon

Selecting all cells in a merged region

In a GridControl, is there a way to cause all cells within a merged region to become selected with a single click so that the merged region can then be dragged and dropped? --Van Baker

6 Replies

AD Administrator Syncfusion Team November 6, 2004 07:49 PM UTC

By merge, you mean MergeCells and not coveredcells, correct? There are no property settings to handle this. One want you can do this is to handle the QueryOleDataSourceData event and set the e.DataObject yourself to hold what cells you want to drag. You would create a string delimited by tab for columns and NewLines for rows, and set the string into the dataobject, also setting e.Handled = true and e.Result = true. Another option would be to handle the CurrentCellMoved event. And there you could add a range to grid.Selections that holds a range of cells that you want to possibly drag.


VB vbaker November 6, 2004 08:51 PM UTC

Thanks, Clay, for your reply. Yes, I do mean merged cells, not covered. I haven''t yet tried your first option, but have tried something similar to your second. I handled MouseDown as follows to isolate the merged cell range: if ((e.Button & MouseButtons.Left) == MouseButtons.Left) { Point pt = this.gridControl1.PointToClient(Control.MousePosition); if (this.gridControl1.PointToRowCol(pt, out Row, out Col)) { this.gridControl1.CurrentCell.AdjustRowColIfCoveredCell(ref Row, ref Col); } //Determine if the clicked cell is part of a MergeCell range GridRangeInfo gri = this.gridControl1.Model.MergeCells.FindRange(Row, Col); if (!gri.IsEmpty) { // Yes, it''s part of a MergeCell range. Select the entire range. this.gridControl1.Selections.SelectRange(gri, true); } } When I click on a cell in a merged range, the entire merged range does, in fact, "appear" selected. However, there is now a "focus" rectangle around the clicked cell, and if I attempt to drag at that point, only the focused cell will drag. In order to select the entire range for dragging, I have to click/drag the mouse over the range of cells, which now appear with a slightly different selection color. It is like there are two different types of "selection", one which will drag, the other which will not, which admittedly, I don''t seem to understand. --Van Baker


AD Administrator Syncfusion Team November 6, 2004 09:04 PM UTC

Try your code in CurrentCellMoved. In the handler, you can try testing for mousedown using the static member, Control.MouseButtons.


VB vbaker November 6, 2004 09:48 PM UTC

I tried your suggestion handling CurrentCellMoved with my code, but still, only the clicked cell will drag. I have to manually re-select the entire range and then drag in order for the entire range to move. Should I be using Covered Cells rather than MergeCells? If so, how to combine multiple cells based on their content? --Van Baker


AD Administrator Syncfusion Team November 7, 2004 06:39 AM UTC

Try your code in MouseUp but first deactivate the currentcell.
private void gridControl1_MouseUp(object sender, MouseEventArgs e)
{
	GridCurrentCell cc = this.gridControl1.CurrentCell;
	GridRangeInfo gri = this.gridControl1.Model.MergeCells.FindRange(cc.RowIndex, cc.ColIndex);
	if (!gri.IsEmpty)
	{
		cc.Deactivate(false);
		this.gridControl1.Selections.SelectRange(gri, true);
	} 
}


VB vbaker November 7, 2004 10:22 AM UTC

Thank you! I appreciate your patience and persistence. That accomplishes exactly what I needed. --Van Baker

Loader.
Live Chat Icon For mobile
Up arrow icon