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 : November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Validating GDBG.CurrentCell values

Thread ID:

Created:

Updated:

Platform:

Replies:

30105 Jun 10,2005 04:34 PM UTC Jun 14,2005 03:40 PM UTC WinForms 10
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On June 10, 2005 04:34 PM UTC

I''m attmpting to implement som validation on user input in a GDBG cell. Should the validation fail, the user should not be able to move the current cell, but the user should be able to use the escape key to trigger the Form.CancelButton. Currently I am: 1. Validating the current cell value in the GDBG.CurrentCellEditingComplete event. and 2. Handling the GDBG.KeyDown event to call the Form.CancelButton.PerformClick() method when the Escape key is presssed. The issue that I am having trouble solving is, should validation fail, the user should not be able to move the current cell until they either enter a valid value or press the escap key and trigger a Form.CancelButton.PerformClick(). I''ve tried setting a flag that will cancel the GDBG.CurrentCellMoving and GDBG.CurrentCellDeactivating events but, bot yeild the begaviour of preventing me from moving of the subsequently moved to cell not the cell that failed validation. Should I be handling cell validation in a different event? When validation fails how can I prevent the current cell from moving and the grid losing focus, while still allowing the Form.CancellButton to be triggered? Thanks in advance for any help! Dave

Administrator [Syncfusion]
Replied On June 10, 2005 06:23 PM UTC

You should use the CurrentCellValidating event. In it, you can use grid.CurrentCell.Renderer.ControlText to get the proposed new value for cell, and validate it. If you set e.Cancel = true, your user will not be able to leave the cell. You can also optionally set grid.CurrentCell.ErrorMassage if you want an error message displayed for your user.

Administrator [Syncfusion]
Replied On June 13, 2005 05:14 PM UTC

Thanks Clay! I have a further question. Using your suggested approach, is there a way to still allow the user to click the Form.CancelButton? i.e. If the user has entered an invalid cell value, they should still be able to click the "Cancel" button on the Form. Thanks, Dave

Administrator [Syncfusion]
Replied On June 13, 2005 06:36 PM UTC

For your cancel button, try setting its button.CausesValidation = false. I think this should allow it to be clicked.

Administrator [Syncfusion]
Replied On June 13, 2005 07:25 PM UTC

Clay, Unfortunately that did not work correct the problem. Setting this.btnCancel.CausesValidation to false still still appears to cause validation on the current cell. Also, I have the grid.WantEscapeKey property set to true so that the escape key will reset cell contents. Simply setting this property does not appear to cause the behaviour I would like. Should the user press the escape key while editing a cell, I''d like it to revert to its original value. Do I actually need to handle the escape key in the CurrentCellKeyDown event? Finally, what is the simplest way to limit user input within an editable cell to positive numeric characters only? Currently I handle keys in the CurrentCellKeyPress event, but would like to know if there''s a better implementation. Thanks again, Dave

Administrator [Syncfusion]
Replied On June 13, 2005 08:46 PM UTC

1) Are you making any calls or handling any events that might interfere with this behavior? Maybe explicitly calling CurrentCell.EndEdit or Binder.EndEdit or handling some focus events? 2) This is default behavior. If you just press escape on an editing cell, it will reset teh value. Here is a sample that shows 1 and 2 working by default. The CurrentCellValidate will cancel if teh length of teh entry is less than 4 characters. But you can still click the button that has Causevalidation = false. 3) If you just want to make sure that only digits are pressed then CurrentCellKeyPress is a good as any event to handle this. But if you need to validate the whole string for some reason, then CurrentCellValidateString is a better place because the whole proposed value is passed in in e.Text.

Administrator [Syncfusion]
Replied On June 13, 2005 10:08 PM UTC

>1) Are you making any calls or handling any events that might interfere with this behavior? Maybe explicitly calling CurrentCell.EndEdit or Binder.EndEdit or handling some focus events? > It does not appear so, the only events that I am currently handling for the gird are: CurrentCell.KeyPress - to ignore non-nmeric characters CurrentCell.KeyDown - to provide different functionality for the delete key when on a non-editable field. CurrentCell.Activated - to conditionally set Grid.EnableEdit. CurrentCell.StartEditing - To conditionally set e.Cancel. CellClick - for some custom right-click functionality. DragOver and DragDrop - for dragging and droping from another grid. I do not have anything defined that should be stealing the focus in between an editing cell and a mouse click on the Cancel button with CausesValidation = false. >2) This is default behavior. If you just press escape on an editing cell, it will reset teh value. > >Here is a sample that shows 1 and 2 working by default. The CurrentCellValidate will cancel if teh length of teh entry is less than 4 characters. But you can still click the button that has Causevalidation = false. > I have the Form.AcceptButton = this.btnCancel, which also means that btnCancel.DialogResult = DialogResult.Cancel. There are no events defined for btnCancel. Strangely Form.CancelButton is ONLY triggered in the grid when in an editing cell NOT a non-editing cell. It appears that if I reset the Form.CancelButton to none, then I get the desired escape key behaviour in an editing cell, however I lose all Escape->Form.CancelButoon functionality within the form. >3) If you just want to make sure that only digits are pressed then CurrentCellKeyPress is a good as any event to handle this. But if you need to validate the whole string for some reason, then CurrentCellValidateString is a better place because the whole proposed value is passed in in e.Text.

Administrator [Syncfusion]
Replied On June 13, 2005 10:25 PM UTC

>>It appears that if I reset the Form.CancelButton to none, then I get the desired escape key behaviour in an editing cell, however I lose all Escape->Form.CancelButoon functionality within the form. You could try conditionally setting Form.CancelButton to none in CurrentCellGotFocus and then resetting it in CurrentCellLostFocus. This may allow the escape to work within the cell whilte the cell is editing, and to work on the form when the cell is not editing.

Administrator [Syncfusion]
Replied On June 14, 2005 01:48 PM UTC

I do not see CurrentCellGotFocus or CurrentCellLostFocus events in either the designer of VS Intellisense. We''re using Essential Suite version 2.1.0.9, in case that makes a difference.

Administrator [Syncfusion]
Replied On June 14, 2005 02:05 PM UTC

Sorry, I left out the word Control. this.gridControl1.CurrentCellControlGotFocus += new ControlEventHandler(gridControl1_CurrentCellControlGotFocus); this.gridControl1.CurrentCellControlLostFocus += new ControlEventHandler(gridControl1_CurrentCellControlLostFocus);

Administrator [Syncfusion]
Replied On June 14, 2005 03:40 PM UTC

Thanks Clay, That solved the issue with the escape key functionality. Also, regarding the CurrentCellValidating event and the btnCancel.CausesValidation = false, the validation was still firing because the btnCancel was contained in a separate panel that had CausesValidation = true. D''oh!! It wokrs fine now that I''ve set the CausesValidation property on the panel to false as well. Thanks! Dave

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

;