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
150
InvalidCastException when DEL key pressed
posted

Hi, I have a weird problem when using the UltraGrid.

I have a basic ultragrid that is bound to a bindingsource that includes items from a bindinglist<T>.

Everything works fine except when the user edits numeric cells and hits DEL / BACKSPACE -button to clear the cell. An unhandled exception pops up with the following message:
------------------------------------------------
System.InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.String'.
   at Infragistics.Win.EditorWithText.Infragistics.Win.IEmbeddableTextBoxListener.OnTextChanged()
   at Infragistics.Win.EmbeddableTextBox.OnTextChanged(EventArgs e)
   at System.Windows.Forms.TextBoxBase.WmReflectCommand(Message& m)
   at System.Windows.Forms.TextBoxBase.WndProc(Message& m)
   at System.Windows.Forms.TextBox.WndProc(Message& m)
   at Infragistics.Win.EmbeddableTextBoxWithUIPermissions.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 should mention that I am using a DataFilter on the some of the cells to format null values.

But how can a trap this exception to get a better idea what's happening?
Anyone have an idea what could be causing this?

Parents
  • 69832
    Verified Answer
    Offline posted

    It looks like EditorWithText directly casts the value obtained during the 'DisplayToEditor' conversion phase to type string, which would explain the exception you are getting. I suppose we could change this to check the type of the returned value first, and/or use the ToString method, which might solve this problem, so you might say this is a bug but I would have to see the code in order to put this in the proper context. The editor's name is EditorWithText after all, so it is reasonable for us to expect that the IEditorDataFilter implementor hand us back strings.

    Most likely you can solve this problem by not returning an integer for that phase, but rather the string representation thereof, i.e., return the resolut of the ToString() method off the value rather than the value itself. I think this will stop the exception.

Reply Children
No Data