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.
Syncfusion Feedback

Disable ability to select multiple cells/rows/columns

Thread ID:

Created:

Updated:

Platform:

Replies:

37397 Nov 21,2005 08:51 PM UTC Nov 22,2005 12:15 AM UTC WinForms 5
loading
Tags: GridControl
Michael Scott
Asked On November 21, 2005 08:51 PM UTC

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?

Administrator [Syncfusion]
Replied On 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.

Michael Scott
Replied On 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; } }

Administrator [Syncfusion]
Replied On 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();
}

Michael Scott
Replied On 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.

Administrator [Syncfusion]
Replied On 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

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.

Warning Icon 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.Close Icon

;