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.

Disable ability to select multiple cells/rows/columns

Thread ID:

Created:

Updated:

Platform:

Replies:

37397 Nov 21,2005 03:51 PM Nov 21,2005 07:15 PM Windows Forms 5
loading
Tags: GridControl
Michael Scott
Asked On November 21, 2005 03:51 PM

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 04:47 PM

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 05:22 PM

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 06:13 PM

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 21, 2005 07:01 PM

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 21, 2005 07:15 PM

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.

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.

;