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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

GridSelectionChanging Event

Thread ID:





37830 Dec 1,2005 12:20 AM UTC Dec 1,2005 10:09 PM UTC WinForms 10
Tags: GridControl
Michael Scott
Asked On December 1, 2005 12:20 AM UTC

The following function works in all cases, except for selecting the last row or column (row/column totals). It looks like e.Range is blank if you click on a cell (other than the border cell). Is this a problem? I''m trying to make the last row/column in the grid be non-clickable, and warn the user to that fact. This code works if I click on the row/column header, but any single cell in that row/column has no values for Left/Right/Top/Bottom, and RangeType is Empty, instead of Cells. What am I doing wrong? private void SelectionChangingEventHandler(object sender, Syncfusion.Windows.Forms.Grid.GridSelectionChangingEventArgs e) { try { // If selection is multirow, don''t allow it if ( (e.Range.RangeType == GridRangeInfoType.Rows) && (e.Range.Height > 1) ) { e.Cancel = true; MessageBox.Show("Only a single row is allowed."); } // If selection is Row Total, don''t allow it else if (e.Range.Bottom == this.rows) { e.Cancel = true; MessageBox.Show("Clicking on Row Totals is not allowed."); } // If selection is multicolumn, don''t allow it else if ( (e.Range.RangeType == GridRangeInfoType.Cols) && (e.Range.Width > 1 ) ) { e.Cancel = true; MessageBox.Show("Only a single column is allowed."); } // If selection is Col Total, don''t allow it else if (e.Range.Right == this.cols) { e.Cancel = true; MessageBox.Show("Clicking on Column Totals is not allowed."); } // If selection is multicell, don''t allow it else if ( (e.Range.RangeType == GridRangeInfoType.Cells) && ( (e.Range.Height > 1) || (e.Range.Width > 1) ) ) { e.Cancel = true; MessageBox.Show("Only a single cell is allowed."); } // If selection is non-contiguous, clear selection if(this.gridCtl.Selections.Count > 1) this.gridCtl.Selections.Clear(); } catch { System.Diagnostics.Debug.Assert(false,"Exception thrown in ConfusionMatrixView.OnSelectionChanging"); } }

Administrator [Syncfusion]
Replied On December 1, 2005 12:36 AM UTC

What kind of style settings do you have for the row/column that behaves differently? For example, is style.Enabled set to false for these cells? If so, that will affect this behavior.

Michael Scott
Replied On December 1, 2005 01:18 AM UTC

After your suggestion regarding GridPrepareViewStyleInfoEvent, I''m not using styles anymore - that I know of, nor am I setting Clickable / Enabled flags. This is the only place styles are even mentioned : private void InitializeComponent() { System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(ConfusionMatrixView)); Syncfusion.Windows.Forms.Grid.GridStyleInfo gridStyleInfo1 = new Syncfusion.Windows.Forms.Grid.GridStyleInfo(); this.gridCtl = new Syncfusion.Windows.Forms.Grid.GridControl(); ((System.ComponentModel.ISupportInitialize)(this.gridCtl)).BeginInit(); this.SuspendLayout(); // // gridCtl // this.gridCtl.AllowSelection = ((Syncfusion.Windows.Forms.Grid.GridSelectionFlags)(((Syncfusion.Windows.Forms.Grid.GridSelectionFlags.Row | Syncfusion.Windows.Forms.Grid.GridSelectionFlags.Column) | Syncfusion.Windows.Forms.Grid.GridSelectionFlags.Cell))); this.gridCtl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.gridCtl.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.gridCtl.ControllerOptions = ((Syncfusion.Windows.Forms.Grid.GridControllerOptions)(((Syncfusion.Windows.Forms.Grid.GridControllerOptions.ClickCells | Syncfusion.Windows.Forms.Grid.GridControllerOptions.SelectCells) | Syncfusion.Windows.Forms.Grid.GridControllerOptions.ExcelLikeSelection))); this.gridCtl.Data = ((Syncfusion.Windows.Forms.Grid.GridData)(resources.GetObject("gridCtl.Data"))); this.gridCtl.DragSelectedCellsMouseButtonsMask = System.Windows.Forms.MouseButtons.None; this.gridCtl.EnterKeyBehavior = Syncfusion.Windows.Forms.Grid.GridDirectionType.None; this.gridCtl.Location = new System.Drawing.Point(0, 0); this.gridCtl.Name = "gridCtl"; this.gridCtl.ResizeColsBehavior = Syncfusion.Windows.Forms.Grid.GridResizeCellsBehavior.None; this.gridCtl.ResizeRowsBehavior = Syncfusion.Windows.Forms.Grid.GridResizeCellsBehavior.None; this.gridCtl.RowCount = 1000; this.gridCtl.SelectCellsMouseButtonsMask = System.Windows.Forms.MouseButtons.Left; this.gridCtl.Size = new System.Drawing.Size(720, 480); this.gridCtl.TabIndex = 0; gridStyleInfo1.CellAppearance = Syncfusion.Windows.Forms.Grid.GridCellAppearance.Flat; gridStyleInfo1.CellType = "Static"; gridStyleInfo1.HorizontalAlignment = Syncfusion.Windows.Forms.Grid.GridHorizontalAlignment.Center; gridStyleInfo1.ReadOnly = true; gridStyleInfo1.ShowButtons = Syncfusion.Windows.Forms.Grid.GridShowButtons.Show; this.gridCtl.TableStyle = gridStyleInfo1; this.gridCtl.Text = "gridCtl"; this.gridCtl.PrepareViewStyleInfo += new Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventHandler(this.PrepareViewStyleInfoEventHandler); this.gridCtl.SelectionChanging += new Syncfusion.Windows.Forms.Grid.GridSelectionChangingEventHandler(this.SelectionChangingEventHandler); this.gridCtl.CellClick += new Syncfusion.Windows.Forms.Grid.GridCellClickEventHandler(this.CellClickEventHandler); // // ConfusionMatrixView // this.Controls.Add(this.gridCtl); this.Name = "ConfusionMatrixView"; this.Size = new System.Drawing.Size(720, 480); ((System.ComponentModel.ISupportInitialize)(this.gridCtl)).EndInit(); this.ResumeLayout(false); }

Administrator [Syncfusion]
Replied On December 1, 2005 01:31 AM UTC

Clicking a single cell does not select it. It makes it the currentcell which is different than adding it to the grid.Selections.Ranges collection which is what selectiong it does. If you do not want the user to be able to click on cells in the last row/column, then try setting e.Style.Enabled = false in your PrepareViewStyleInfo event handler for those cells.

Michael Scott
Replied On December 1, 2005 01:41 AM UTC

What''s the difference between enabled and clickable?

Administrator [Syncfusion]
Replied On December 1, 2005 02:07 AM UTC

Setting Enabled = false means the cell cannot become the currentcell. Clickable determines whethe rthe grid.Cellclick event is raised when you click on a cell.

Michael Scott
Replied On December 1, 2005 02:45 AM UTC

If I set the cell to have "Enabled" = false in the GridPrepareViewStyleInfoEvent event, then catch the GridCellClickEvent if I click on that cell, CurrentRange is really the last valid cell - which means I''m performing an action on the last valid cell I selected. How can I get past that?

Administrator [Syncfusion]
Replied On December 1, 2005 08:54 AM UTC

In the CellClick event, the cell clicked is given by e.RowIndex and e.ColIndex. If you need a range, you can use GridRangeInfo.Cell(e.RowIndex, E.ColIndex). Exactly what is it you are trying to do if the clicks a cell in the last row or column? If you just want to display a message, then you can test e.RowIndex and e.ColIndex to see if they are respectively, grid.Model.RowCount or ColCount to determine whether to show the message. You would not rely on SelectionChnaging in this case.

Michael Scott
Replied On December 1, 2005 08:43 PM UTC

Clay, What I''m trying to do is have the last row / column be for information purposes only (row/column totals). I''d prefer to let the user know that this is an un-clickable region, but would be OK with just being a no-op. Instead, I''m falling into the GridCellClickEvent event handler, but the cell it''s looking at is the last VALID cell I clicked. Attached is a ZIP file containing the code in question, as well as a picture of what the matrix looks like. Perhaps I''m not understanding this line of code : this.gridCtl.Selections.GetSelectedRanges (out rangeList, bConsiderCurrentCell) On clicking of a disabled cell, it''s returning the last enabled cell I clicked on. I can live with the CellClick event handler catching this, but I want it to fall through and do NOTHING if the cell/row/col is disabled. Am I barking up the wrong tree here??? Michael


Administrator [Syncfusion]
Replied On December 1, 2005 09:56 PM UTC

This is by design. The currentcell will not change when you click a disabled cell. So, if you do not want anything to happen when you click a cell in the last row or last column, try adding this code at the top of you CellClick event handler.
if((e.RowIndex == this.gridCtl.RowCount && e.ColIndex > 0)
				|| (e.ColIndex == this.gridCtl.ColCount && e.RowIndex > 0))
Or, if you want to process a range of the clicked cell in the case when you click on the last row/col, then define the rangeList by creating a new GridRangeInfoList and adding this GridRangeInfo.Cell(e.RowIndex, e.ColIndex) to it instead of calling GetSelectedRanges to define it.

Michael Scott
Replied On December 1, 2005 10:09 PM UTC

Got it. I kept thinking by e.RowIndex and e.ColIndex that you were referring to the current range. I finally figured out what you were saying earlier after I took these two properties literally - and added the same code you just posted. Thanks for all the help.


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