Hi community
I'm using an ultranumericeditor on my form with nullable-property set to true.
Now, if I insert some value into it and remove the same again, the Value-property isn't null as I expected. It is of type DbNull.
Is that a bug? Or could I edit any settings to control that?
I'm using NetAdvantage 2011.1
Thx for helping me!
Hi,
I tried it out and I get the results you describe. I guess it does this just in case the Value property is bound to a data source.
You can, of course, have your code check for DBNull as well as null, but I can understand how that might be a bit of a pain to do that everywhere in your application.
So another way you could deal with this is to use a DataFilter to convert the text into the value you want (null). Here's a sample DataFilter class I whipped up. You can create a single instance of this class and set the DataFilter of all your UltraNumericEditors to the same instance.
public class MyNullDataFilter : IEditorDataFilter { #region IEditorDataFilter Members object IEditorDataFilter.Convert(EditorDataFilterConvertArgs conversionArgs) { switch (conversionArgs.Direction) { case ConversionDirection.DisplayToEditor: string s = conversionArgs.Value.ToString().Trim(); if (String.IsNullOrEmpty(s)) { // When the user enters an empty string, return null instead of // DBNull.Value. conversionArgs.Handled = true; return null; } break; } // Do nothing. return null; } #endregion }
Hi Mike
Thanks for your reply.
No, it's an unbound control.
Control in Designer.cs:
// // numericEditor// this.numericEditor.Location = new System.Drawing.Point(124, 19);this.numericEditor.MaxValue = 120;this.numericEditor.MinValue = 1;this.numericEditor.Name = "tbLUExpirationDuration";this.numericEditor.Nullable = true;this.numericEditor.PromptChar = ' ';this.numericEditor.Size = new System.Drawing.Size(62, 21);this.numericEditor.SpinButtonDisplayStyle = Infragistics.Win.ButtonDisplayStyle.Always;this.numericEditor.SpinIncrement = 1;this.numericEditor.TabIndex = 15;this.numericEditor.Value = null;
Is the control's Value bound to a DataSource? If so, I expect it's the DataSource using DBNull. In which case, you could handle the Parse/Format events on the Binding.