This is a migrated thread and some comments may be shown as answers.

How can I disable selecting on one whole row or column

3 Answers 318 Views
Spreadsheet
This is a migrated thread and some comments may be shown as answers.
wen
Top achievements
Rank 1
wen asked on 13 Nov 2019, 02:57 AM

Hello, 

 

When a worksheet shows, not all columns or rows would display. But clicking on column header, like "A", "B", or row number "1","2", etc. is going to select the whole row or column. Is there a way to disable this kind of row and column selection? Or, what's the event of clicking on the column header and row number? 

Thanks.

3 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 15 Nov 2019, 04:24 PM

Hi Wen,

You can achieve the desired functionality by attaching to the Selection`s SelectionChanging event using the ActiveWorksheetEditor.

this.radSpreadsheet.ActiveWorksheetEditor.Selection.SelectionChanging += this.Selection_SelectionChanging;
In the following example, we check if the selection range hits the maximum row or column number and if so we cancel the selection because this means the whole row or column will be selected:
private void Selection_SelectionChanging(object sender, SelectionChangingEventArgs e)
{
	foreach (CellRange range in e.NewSelectedRanges)
	{
		if (range.ColumnCount == SpreadsheetDefaultValues.ColumnCount || range.RowCount == SpreadsheetDefaultValues.RowCount)
		{
			e.Cancel();
		}
	}
}

I hope this helps. Don't hesitate to contact us if any additional questions arise.

Regards,
Martin
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
wen
Top achievements
Rank 1
answered on 15 Nov 2019, 04:59 PM

Hi Martin,

Thanks for your reply. 

I also achieved it with another workaround by cancelling mouse clicking event when the cursor position is not on the sheet.

But Martin, could you help me understand one more thing - what happens when visit section.IsRowSelection and IsColumnSelection? I tried "e.Handled = true" in these two conditions, it didn't work. But when I simply try "e.Handled = true" if the cursor position is on the board, it works.

0
Martin
Telerik team
answered on 20 Nov 2019, 11:48 AM

Hello Wen,

The properties IsRowSelection and IsColumnSelection are returning a boolean value based on whether the selection contains a whole row or column. They are using the same approach to determine if the selection consists of the whole row/column:

if (range.RowCount != SpreadsheetDefaultValues.RowCount)
{
	return false;
}

but the main difference is that when using the NewSelectedRanges of the SelectionChangingEventArgs you are checking the selection before it is applied and the selection.IsRowSelection (or selection.IsColumnSelection) is checking the selection after it is already selected. Thus, the different approaches give different results. 

As for the used workaround, yes, canceling the mouse clicking event when the cursor position is not on the sheet is another possible way to achieve the desired functionality.

Regards,
Martin
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Spreadsheet
Asked by
wen
Top achievements
Rank 1
Answers by
Martin
Telerik team
wen
Top achievements
Rank 1
Share this question
or