Using MaskEdit with a Date Column
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
SIGN IN To post a reply.
5 Replies
AD
Administrator
Syncfusion Team
January 11, 2006 01:26 PM UTC
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
VB39542.zip
CE
Chad Elliot
May 1, 2006 09:00 PM UTC
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?
AD
Administrator
Syncfusion Team
May 2, 2006 07:12 AM UTC
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
VB39542C.zip
CE
Chad Elliot
May 2, 2006 01:39 PM UTC
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.
AD
Administrator
Syncfusion Team
May 3, 2006 05:29 AM UTC
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
VB395420.zip
SIGN IN To post a reply.
- 5 Replies
- 2 Participants
-
CE Chad Elliot
- Jan 10, 2006 11:03 PM UTC
- May 3, 2006 05:29 AM UTC