maskedit in cell of gridControl

hi to all, i''m using the gridControl in my win form application. i have a cell that contains a maskedit, i set the property Mask like this : oGrdC.ColStyles[i + 1].MaskEdit.Mask = "__/__/___"; when i run the program, i can''t enter data. i works only when i set the property to " / / " how can i put the first mask ("__/__/____") for the date best regards and thanks in advance fady

10 Replies

AD Administrator Syncfusion Team April 21, 2006 03:55 AM UTC

Hi Fady, Could you try this code oGrdC.ColStyles[i + 1].CellType = "MaskEdit"; oGrdC.ColStyles[i + 1].MaskEdit.Mask = "99/99/9999"; Let me know if you need any further assistance. Regards, Haneef


FS Fady Sayegh April 21, 2006 07:28 AM UTC

Hi Haneef, thanks to your reply, in fact that''s what did i do, but this 2 lines of code oGrdC.ColStyles[i + 1].CellType = "MaskEdit"; oGrdC.ColStyles[i + 1].MaskEdit.Mask = "99/99/9999"; gives this mask at run time " / / " or i need to have this one "__/__/____", in other words i need to display the underscores in the mask. but when i do that the gridControl does not accept any input from the user in the maskedit cell best regards and thanks in advance fady


AD Administrator Syncfusion Team April 21, 2006 08:54 AM UTC

Hi Fady, You need to set the PaddingCharacter and PromptCharacter property of the MaskEdit Celltype in a grid.Here is a code snippet. oGrdC.ColStyles[i + 1].CellType = "MaskEdit"; oGrdC.ColStyles[i + 1].MaskEdit.Mask = "99/99/9999"; oGrdC.ColStyles[i + 1].MaskEdit.PromptCharacter = ''_''; oGrdC.ColStyles[i + 1].MaskEdit.PaddingCharacter = ''_''; Here is a sample. http://www.syncfusion.com/Support/user/uploads/welcome_966bb1ae.zip Let me know if you need any further assistance. Regards, Haneef


FS Fady Sayegh April 21, 2006 10:10 AM UTC

Hi Haneef, thanks to your reply, it works but how can i verify if the date (54/26/2006)entered by the user is valid. is there a way to validate the date when the user leave the cell for example, if the date is not valid and when the user leave the cell : clear the cell best regards and thanks in advance fady


AD Administrator Syncfusion Team April 21, 2006 10:49 AM UTC

Hi Fady, To validate the current cell in a grid, you need to handle grid''s CurrentCellValidateString event.Here is a code snippet GridCurrentCell cc = this.gridControl1.CurrentCell; CultureInfo culture = new CultureInfo(CultureInfo.CurrentCulture.LCID); try { DateTime.ParseExact( cc.Renderer.ControlText,"dd/MM/yyyy",culture,DateTimeStyles.AllowWhiteSpaces ); } catch { cc.RejectChanges(); } Please let me know if you have any further assistance. Thanks for your interest in Syncfusion Products. Regards, Haneef


FS fady sayegh April 21, 2006 01:58 PM UTC

Hi Haneef, thanks to your reply, the code you gave work properly, but when i type an invalide date "35/35/2006" and hit the tab key nothing happens the first time, i need to hit another time the tab key so the changes will be rejected. so the changes are rejected the second time i hit the tab key and not the first time. do you have any idea to solve this issue ? best regards and thanks in advance fady


AD Administrator Syncfusion Team April 24, 2006 03:45 AM UTC

Hi Fady, Could you try this code. GridCurrentCell cc = this.gridControl1.CurrentCell; CultureInfo culture = new CultureInfo CultureInfo.CurrentCulture.LCID); try { DateTime.ParseExact( cc.Renderer.ControlText,"dd/MM/yyyy",culture,DateTimeStyles.AllowWhiteSpaces ); } catch { cc.Renderer.ControlValue = string.Empty; } Thanks for your patience. Regards, Haneef


FS Fady Sayegh April 24, 2006 08:51 AM UTC

Hi Haneef, thanks to your reply, the code you post work properly, but it set the cell to empty if the user enter a wrong date. but i still need the old value of the cell. for example : the value in the cell before editing is "12/12/2005", now the user enter a wrong date "35/35/2005". when the user hit the tab key i need to get back to the old date witch is "12/12/2005" and not an empty string best regards and thanks in advance fady


AD Administrator Syncfusion Team April 24, 2006 09:48 AM UTC

Hi Fady, You need to use this code to get the old value of the cell in a grid.Here is a code snippet GridCurrentCell cc = this.gridControl1.CurrentCell; CultureInfo culture = new CultureInfo( CultureInfo.CurrentCulture.LCID); try { DateTime.ParseExact( cc.Renderer.ControlText,"dd/MM/yyyy",culture,DateTimeStyles.AllowWhiteSpaces ); } catch { cc.Renderer.ControlValue = this.gridControl1.Model[cc.RowIndex,cc.ColIndex].CellValue ; } Please let me know if this helps. Regards, Haneef


FS Fady Sayegh April 24, 2006 10:15 AM UTC

Hi Haneef, thanks to your reply, it works fine, that''s exactly what did i want thanks again fady

Loader.
Up arrow icon