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

Disable ability to select multiple cells/rows/columns

It turns out the grid control I''m working on should only allwo the user to select a single cell, a single row, or a single column. How do I disable the drag/select ability to select multipe rows/columns/cells?

5 Replies

AD Administrator Syncfusion Team November 21, 2005 09:47 PM UTC

If this is a GridControl or GridDataBoundGrid, you can handle the grid.Model.SelectionChanging event. If e.Range is something you do not want selected, then set e.Cancel = true.


MS Michael Scott November 21, 2005 10:22 PM UTC

OK, I''m now doing as you ask (see below), but now, if I select a single row or column, only the 1st time will the entire row/column get highlighted. How can I continue to have the selected row/column highlighted? private void OnSelectionChanging(object sender, Syncfusion.Windows.Forms.Grid.GridSelectionChangingEventArgs e) { e.Cancel = false; bool bSingleRow = (e.Range.Top == e.Range.Bottom); bool bSingleCol = (e.Range.Left == e.Range.Right); bool bSingleCell = bSingleRow && bSingleCol; switch(e.Range.RangeType) { case GridRangeInfoType.Cells: if (!bSingleCell) e.Cancel = true; break; case GridRangeInfoType.Cols: if (!bSingleCol) e.Cancel = true; break; case GridRangeInfoType.Rows: if (!bSingleRow) e.Cancel = true; break; case GridRangeInfoType.Table: e.Cancel = true; break; default: e.Cancel = true; break; } }


AD Administrator Syncfusion Team November 21, 2005 11:13 PM UTC

Try this code to see if it gives you what you want.
private void Model_SelectionChanging(object sender, GridSelectionChangingEventArgs e)
{
	if(e.Range.RangeType == GridRangeInfoType.Rows && e.Range.Height > 1)
	{
		e.Cancel = true;
	}
	else if(e.Range.RangeType == GridRangeInfoType.Cols && e.Range.Width > 1)
	{
		e.Cancel = true;
	}
	else if(e.Range.RangeType == GridRangeInfoType.Cells 
		&& (e.Range.Height > 1 || e.Range.Width > 1))
	{
		e.Cancel = true;
	}
	if(this.gridControl1.Selections.Count > 1)
		this.gridControl1.Selections.Clear();
}


MS Michael Scott November 22, 2005 12:01 AM UTC

No, it doesn''t. If I click on row 2, the row turns blue. If I then click on row 7, row 2 is still blue (selected), but row 7 isn''t. Only that 1st selection highlights.


AD Administrator Syncfusion Team November 22, 2005 12:15 AM UTC

Using version 3.3, this sample allows me to click the header of row 2 and then click the header of row 7 only leaving row 7 selected. Does it work that way for you? http://www.syncfusion.com/Support/user/uploads/GC_Selections_cc52df28.zip

Loader.
Live Chat Icon For mobile
Up arrow icon