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.

Using MaskEdit with a Date Column

Thread ID:

Created:

Updated:

Platform:

Replies:

39542 Jan 10,2006 06:03 PM May 3,2006 01:29 AM Windows Forms 5
loading
Tags: GridControl
Chad Elliot
Asked On January 10, 2006 06:03 PM

I have a data grid displaying the data from the Northwind.dbo.Orders table. I want to use an input mask for the OrderDate column. My code so far looks like this: Dim oStyle As New Syncfusion.Windows.Forms.Grid.GridStyleInfo Dim oMask As Syncfusion.Windows.Forms.Grid.GridMaskEditInfo = oStyle.MaskEdit Dim oGridBoundColumn As Syncfusion.Windows.Forms.Grid.GridBoundColumn oGridBoundColumn = New Syncfusion.Windows.Forms.Grid.GridBoundColumn oGridBoundColumn.HeaderText = "OrderID" oGridBoundColumn.MappingName = "OrderID" oGridBoundColumn.StyleInfo.CellType = "TextBox" GridDataBoundGrid1.GridBoundColumns.Add(oGridBoundColumn) oStyle.CellType = "MaskEdit" oStyle.CellValueType = GetType(System.DateTime) oStyle.CultureInfo = New System.Globalization.CultureInfo("en-US", False) oStyle.Format = "MM/dd/yy" oMask.Mask = "99/99/99" oMask.DateSeparator = "/" oGridBoundColumn = New Syncfusion.Windows.Forms.Grid.GridBoundColumn oGridBoundColumn.HeaderText = "OrderDate" oGridBoundColumn.MappingName = "OrderDate" oGridBoundColumn.StyleInfo = oStyle GridDataBoundGrid1.GridBoundColumns.Add(oGridBoundColumn) When I try to change the date of an existing record, I get a message box stating "Cannot set Column ''OrderDate'' to be null. Please use DBNull instead. Also, the following is displayed in the Immediate Window in VS. System.ArgumentException: Cannot set Column ''OrderDate'' to be null. Please use DBNull instead. at System.Data.DataRow.set_Item(DataColumn column, Object value) at System.Data.DataRowView.SetColumnValue(DataColumn column, Object value) at System.Data.DataColumnPropertyDescriptor.SetValue(Object component, Object value) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.SaveCellInfo(GridSaveCellInfoEventArgs e) System.ArgumentException: Cannot set Column ''OrderDate'' to be null. Please use DBNull instead. at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.SaveCellInfo(GridSaveCellInfoEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.Syncfusion.Windows.Forms.Grid.IGridModelDataProvider.SaveCellInfo(GridSaveCellInfoEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModel.SetCellInfo(Int32 rowIndex, Int32 colIndex, GridStyleInfo style, StyleModifyType modifyType, Boolean dontRaiseSaveCellInfoEvent, Boolean copyReferenceOnly) at Syncfusion.Windows.Forms.Grid.GridModel.ChangeCells(GridRangeInfo range, GridStyleInfo[] cellsInfo, StyleModifyType modifyType) at Syncfusion.Windows.Forms.Grid.GridModel.Syncfusion.Windows.Forms.Grid.IGridVolatileDataContainer.ChangeCell(Int32 rowIndex, Int32 colIndex, GridStyleInfo style) at Syncfusion.Windows.Forms.Grid.GridVolatileData.set_Item(Int32 rowIndex, Int32 colIndex, GridStyleInfo value) at Syncfusion.Windows.Forms.Grid.GridStyleInfoIdentity.OnStyleChanged(StyleInfoBase style, StyleInfoProperty sip) at Syncfusion.Styles.StyleInfoBase.OnStyleChanged(StyleInfoProperty sip) at Syncfusion.Windows.Forms.Grid.GridStyleInfo.OnStyleChanged(StyleInfoProperty sip) at Syncfusion.Styles.StyleInfoBase.SetValue(StyleInfoProperty sip, Object value) at Syncfusion.Windows.Forms.Grid.GridCellRendererBase.OnSaveChanges() at Syncfusion.Windows.Forms.Grid.GridCurrentCell.ConfirmChanges(Boolean closeDropDown) System.ArgumentException: Cannot set Column ''OrderDate'' to be null. Please use DBNull instead. at Syncfusion.Windows.Forms.Grid.GridCurrentCell.ConfirmChanges(Boolean closeDropDown) at Syncfusion.Windows.Forms.Grid.GridCurrentCell.Deactivate(Boolean discardChanges) System.ArgumentException: Cannot set Column ''OrderDate'' to be null. Please use DBNull instead. at Syncfusion.Windows.Forms.Grid.GridCurrentCell.Deactivate(Boolean discardChanges) at Syncfusion.Windows.Forms.Grid.GridCurrentCell.MoveTo(Int32 rowIndex, Int32 colIndex, GridSetCurrentCellOptions options, Boolean discardChanges) at Syncfusion.Windows.Forms.Grid.GridSelectCellsMouseController.MouseDown(MouseEventArgs e) at Syncfusion.Windows.Forms.MouseControllerDispatcher.ProcessMouseDown(MouseEventArgs e) at Syncfusion.Windows.Forms.ScrollControllMouseControllerDispatcher.ScrollControlBeforeMouseDown(Object sender, CancelMouseEventArgs e) at Syncfusion.Windows.Forms.ScrollControl.OnScrollControlMouseDown(CancelMouseEventArgs e) at Syncfusion.Windows.Forms.Grid.GridControlBase.OnScrollControlMouseDown(CancelMouseEventArgs e) at Syncfusion.Windows.Forms.ScrollControl.RaiseCancelMouseEvent(MouseEventArgs e, CancelMouseDelegate d) I am using Visual Studio 2005 and SyncFusion version 4.102.0.10. Thanks, Chad

Administrator [Syncfusion]
Replied On January 11, 2006 08:26 AM

Hi Chad, MaskEdit can not be used for a DateTime cell value type. By handling GridDataBoundGrid.Model.QueryCellFormattedText, GridDataBoundGrid.CurrentCellKeyPress, and GridDataBoundGrid.CurrentCellValidating events we can probably get the MaskEdit behavior as in the sample below. Regards, Calvin.

VB39542.zip

Chad Elliot
Replied On May 1, 2006 05:00 PM

Calvin, I’m running into a problem with the sample you sent me. If you use the arrow keys to enter the date cell instead of clicking on the cell with the mouse, the cell does not get activated. When the user starts typing, the 00/00/00 formatting goes away. The only way to get around this is to press the F2 key or change the ActivateCurrentCellBehaviour property of the data grid to SelectAll. I would prefer not to change the ActivateCurrentCellBehaviour property. Any ideas on how to make this work?

Administrator [Syncfusion]
Replied On May 2, 2006 03:12 AM

Hi Chad, The mentioned problem can be avoided by just calling the currentCellRenderer.BeginEdit() in the CurrentCellKeyPress event handler. Attached is the modified sample. Regards, Calvin.

VB39542C.zip

Chad Elliot
Replied On May 2, 2006 09:39 AM

Thanks for the update. I had to tweak it a little to make it work for new records, but it worked perfect for existing records. The date mask is almost perfect, but I have one more request. Is there a way to have the 00/00/00 only show up when you edit the cell? I would prefer not to have 00/00/00 show up in all date cells if there is no date entered.

Administrator [Syncfusion]
Replied On May 3, 2006 01:29 AM

Hi Chad, In the Model.QueryCellFormattedText event handler by cheking the e.TextInfo property and only if the call is orginated for Display text then setting the e.Text to “00/00/00” will give the intent behavior. Please refer to the modified sample which also allow to delete a cell to set the null value when the cell is selected and not in edit mode. Regards, Calvin.

VB395420.zip

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.

;