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?
I'm not particularly fond of this answer. The EditorWithText should imply "Editor of a value that can be represented as text", that's the whole point of the four conversion directions.
I'm developing my first DataFilter, and it's frustrating. In the absence of solid documentation, The view I formed in my mind of the terminology in the editor is as follows,
Owner: The underlying data model that represents the data being shown in the cell being edited in the text box
Editor: The View Model object that the editor has assigned to it's Value property
Display: The View, when using a text editor this is the text representation of the View Model.
I don't think that it is right that the EditorWithText does a direct cast, having editors make that assumption completely destroys the entire purpose of the data filter, you may as well just have the Display and the Owner.
Thanks Brian, changing the return type in the datafilter did the trick.
As a side note, my datafilter is based on Mike Saltzman's ZeroAsBlankDataFilter example from another post. In case you want to debug the IEditorDataFilter interface.
You may also want to set the Visual Studio IDE to break on all run-time exceptions. An exception might be occurring inside your DataFilter, but the grid is catching it so you are only seeing the result and not the cause.
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.