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.

Custom date format error presentation in GDBG ValidateFailed

Thread ID:

Created:

Updated:

Platform:

Replies:

14339 May 25,2004 09:39 AM May 26,2004 10:44 AM Windows Forms 5
loading
Tags: GridControl
Gene Gorokhovsky
Asked On May 25, 2004 09:39 AM

Hi, we are using GDBG 1.6.1.6. When a user commits an edit to a datetime cell, if the string typed in cannot be converted to DateTime, by default grid displays a pop-up message box. Unfortunately, for many reasons, this default behavior is unacceptable for our application, which follows highly specific and regulated UI guidelines. The desired behavior is to 1) display an image and a tooltip inside the cell 2) keep cell in the edit mode with the incorrect value as the current text We overrode OnValidateFailed, setting e.Handled to true, clearing CurrentCell.ErrorMessage to cancel the display of the message box by grid and setting the ColumnError in the underlying DataTable. We override OnPrepareViewStyleInfo to display the error + tooltip when we detect that a validation rule failed. OnPrepareViewStyleInfo takes the error information from the RowError/ColumnError of the underlying DataTable. While it works correctly for various logic tests, sadly redraw needed for OnPrepareViewStyleInfo to do its magic is not triggered for the errors of the above kind. We could not find a way to force repaint of the cell to display the error image. None of the usual suspects, called from the OnValidateFailed, helped. We tried grid.Invalidate*, grid.Refresh*, CurrentCell.Refresh and hitting the monitor with a fist. A solution would be tremendously appreciated. The root cause of this issue is that user can type in something that is not a date. If only Syncfusion grid had a true support for the DatePicker... Gene Gorokhovsky

Administrator [Syncfusion]
Replied On May 25, 2004 10:41 AM

Here is a KB link on one try at putting a DateTimePicker in a grid cell control. http://www.syncfusion.com/Support/article.aspx?id=10435 I tried to see the problem in the sample below and could not. Now this sample does not try to instantiate a tooltip, but does color the cell cell red when there is an error in PrepareViewStyleInfo. So, you might try that (just changing the backcolor) when there is an error. If that works, then the likely problem is not the cell being refreshed, but just the cell cannot handle the tooltip at that point. PreparePareViewStyleInfo is used just to set visual properties used in drawing the cell. But if you want to dynamically change non-visual properties, then setting them in PrepareviewStyleInfo may not be sufficient. The classic example of this is trying to set ReadOnly. It does not work if you set it in PrepareViewstyleinfo, but will work if you set it in Model.QueryCellInfo. This latter event is hit when the style is first requested and before the style used in any manner. Setting a property like ReadOnly at is point does make the cell readOnly, but setting it later in PrepareViewStyleInfo is too late. So, if coloring the cell works, but setting a tootip does not, you might try moving this code from PrepareViewStyleInfo to Model.QueryCellInfo. ForumError_3577.zip

Gene Gorokhovsky
Replied On May 26, 2004 06:02 AM

>Here is a KB link on one try at putting a DateTimePicker in a grid cell control. Thanks. This is a bit raw for my application (I need a dropdown version, with dropdown button even when cell is not edited, and MS control''s drop-down button does not resize like other buttons on the grid) Anyway, your example helped me find a crucial error in my code - I was not setting SetColumnError correctly (in a subtle way because my code is generic with respect to sort and column order). After fixing that, I got almost where I needed. By the way, PrepareViewStyleInfo does work for images and tooltips. A small ( I hope )issue remains. Once user makes a mistake in the date format, and attempts to shift focus to a different cell, grid correctly refuses let go. I need, however, a way to cancel out of this programmatically, upon an external event, such as button click (so the form can be closed etc.) CurrentCell.CancelEdit and CurrentCell.RejectChanges do not do the trick for me. Could you please help? I have attached your code modified with a couple of buttons.

Gene Gorokhovsky
Replied On May 26, 2004 06:04 AM

Here is the example I forgot to attach to my previous posting. Thanks, Gene ForumError_8674.zip

Administrator [Syncfusion]
Replied On May 26, 2004 06:20 AM

There are several of ways to handle this. Here is a .NET solution using Control.CausesValidation. If you do not want a button click to force validation, then you can set its CausesValidation property to false. This will allow you to click the button without validation being triggerred in the control losing focus. This will alow you to close the form even if the current cell is invalid. this.buttonClose.CausesValidation = false; A grid solution would be to handle CurrentCellValidating, and if grid.CurrentCell.IsInMoveTo is false, the focus is leaving the grid. At that point, you can call grid.CurrentCell.CancelEdit() and the validation within the grid will not happen allowing the grid to lose focus.

Gene Gorokhovsky
Replied On May 26, 2004 10:44 AM

Thank you Clay! With the small caveat that CausesValidation has also be false for all container controls of the button in question, your advice has worked perfectly. Gene

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.

;