Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
880
Input string was not in a correct format error on clicking Date cell Drop Down.
posted

Hi,

I'm using a Data Filter to bind objects to a grid and I need to be able to enter dates for certain columns. If I type the date/time directly into the cell (using the input mask) then it works fine. However, if I click on the drop down button I get the following:

Input string was not in a correct format.(System.FormatException: Input string was not in a correct format.
   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseDecimal(String value, NumberStyles options, NumberFormatInfo numfmt)
   at System.Convert.ToDecimal(String value, IFormatProvider provider)
   at Infragistics.Win.UltraWinMaskedEdit.EditInfo.MinValueForMask(Object minValue, String mask)
   at Infragistics.Win.UltraWinMaskedEdit.EditInfo.CalculateTrueMinValue()
   at Infragistics.Win.MonthDropDown.DoDropDown(EmbeddableUIElementBase element)
   at Infragistics.Win.DateTimeEditor.DoDropDown()
   at Infragistics.Win.EmbeddableEditorBase.DropDown()
   at Infragistics.Win.DateTimeEditorDropDownButtonUIElement.OnMouseDown(MouseEventArgs e, Boolean adjustableArea, UIElement& captureMouseForElement)
   at Infragistics.Win.ControlUIElementBase.ProcessMouseDownHelper(Object sender, MouseEventArgs e)
   at Infragistics.Win.ControlUIElementBase.ProcessMouseDown(Object sender, MouseEventArgs e)
   at Infragistics.Win.Utilities.ProcessEvent(Control control, ProcessEvent eventToProcess, EventArgs e)
   at Infragistics.Win.UltraControlBase.OnMouseDown(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam))

I've created a small test form to show the problem (just create a form and stick a grid on it):

Imports Infragistics.Win

Public Class DateDropDownTest

Private mValueDt As New DataTable

Private Sub DateDropDownTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

mValueDt.Columns.Add("DateCol", GetType(ValueObject))

mValueDt.Rows.Add(New Object() {New ValueObject})

mValueDt.Rows.Add(New Object() {New ValueObject(DateTime.Now)})

UltraGrid1.DataSource = mValueDt

Dim gridCol = UltraGrid1.DisplayLayout.Bands(0).Columns(0)

Dim dateEd = New Infragistics.Win.DateTimeEditor

dateEd.DataFilter = New ValueObjectDataFilter

gridCol.Editor = dateEd

gridCol.Style = UltraWinGrid.ColumnStyle.DateTime

gridCol.MaskInput = "{date} {longtime}"

End Sub

End Class

Public Class ValueObject

Private mDateVal As DateTime

Public Sub New()

mDateVal = DateTime.MinValue

End Sub

Public Sub New(ByVal val As DateTime)

mDateVal = val

End Sub

Public Function GetValue() As Object

If mDateVal = DateTime.MinValue Then

Return Nothing

Else

Return mDateVal

End If

End Function

Public Sub SetValue(ByVal val As DateTime)

mDateVal = val

End Sub

End Class

Public Class ValueObjectDataFilter

Implements Infragistics.Win.IEditorDataFilter

Public Function Convert(ByVal conversionArgs As Infragistics.Win.EditorDataFilterConvertArgs) As Object Implements Infragistics.Win.IEditorDataFilter.Convert

Return Convert(conversionArgs.Value, conversionArgs.Context, conversionArgs.Direction, conversionArgs.Handled)

End Function

Public Function Convert(ByVal value As Object, ByVal context As Object, ByVal direction As ConversionDirection, ByRef handled As Boolean) As Object

Dim cell As Infragistics.Win.UltraWinGrid.UltraGridCell

'Check that the object passing through the filter is a grid cell.

If TypeOf context Is Infragistics.Win.UltraWinGrid.UltraGridCell Then

cell = DirectCast(context, Infragistics.Win.UltraWinGrid.UltraGridCell)

Else

Return value

End If

'Action taken depends on the conversion direction.

Select Case direction

Case ConversionDirection.DisplayToEditor

'Do nothing

Case ConversionDirection.EditorToDisplay

If TypeOf cell.Value Is ValueObject Then

handled = True

Return DirectCast(cell.Value, ValueObject).GetValue.ToString

End If

Case ConversionDirection.EditorToOwner

'If the value of the cell is a SamplesViewDataItem then handle the editing of the value.

If TypeOf cell.Value Is ValueObject Then

handled = True

If value IsNot Nothing AndAlso value IsNot DBNull.Value Then

DirectCast(cell.Value, ValueObject).SetValue(CType(value, DateTime))

End If

Return cell.Value

End If

Case ConversionDirection.OwnerToEditor

'If the value of the cell is a SamplesViewDataItem then handle the display of the value.

If TypeOf cell.Value Is ValueObject Then

handled = True

Return DirectCast(cell.Value, ValueObject).GetValue

End If

End Select

Return value

End Function

End Class

Any ideas how I can get the drop down to work?

Thanks,

John.