I have a UltraNumericEditor:
ultraNumericEditor1.NumericType = NumericType.Double; ultraNumericEditor1.DataFilter = new PercentageDataFilter(); ultraNumericEditor1.MaskInput = "nnn\\%"; ultraNumericEditor1.SpinButtonDisplayStyle = Infragistics.Win.ButtonDisplayStyle.Always; ultraNumericEditor1.MaxValue = 100; ultraNumericEditor1.FormatString = "##0\\%";
ultraNumericEditor1.NumericType = NumericType.Double;
ultraNumericEditor1.DataFilter = new PercentageDataFilter();
ultraNumericEditor1.MaskInput = "nnn\\%";
ultraNumericEditor1.SpinButtonDisplayStyle = Infragistics.Win.ButtonDisplayStyle.Always;
ultraNumericEditor1.MaxValue = 100;
ultraNumericEditor1.FormatString = "##0\\%";
When I delete all numbers from the control, that exception is raised from i-don't-know-where, but is not my code, and I don't know how avoid it.
How could I avoid the user introduce values with the keyboard? I only want that the user can modify de value with the spin buttons.
Cheers
Are you sure that the exception is not triggered by your DataFilter (i.e. it's in the call stack somewhere)? I haven't hit this error before, and it's hard to say what's going on just with the information that you provided.
-Matt
Hi, it's vtortola from another computer.
I've copied the datafilter from the KB, and the exception is raised before enter inside it. The exception appears in the entry point of the application (Application.Run(new ClientForm())).
I'm very sure that is not in my code :
Find all "section is empty", Match case, Subfolders, Find Results 1, "Entire Solution" Matching lines: 0 Matching files: 0 Total files searched: 479
And the call stack shows that the exception come from Infragistics, take a look:
Infragistics2.Win.v8.1.dll!Infragistics.Win.UltraWinMaskedEdit.NumberSection.ToDecimal() + 0x7a bytes Infragistics2.Win.v8.1.dll!Infragistics.Win.UltraWinMaskedEdit.NumberSection.CanSpin(bool up = false) + 0x55 bytes Infragistics2.Win.v8.1.dll!Infragistics.Win.UltraWinMaskedEdit.EditInfo.CanSpin(bool up = false) + 0x1f1 bytes Infragistics2.Win.v8.1.dll!Infragistics.Win.EditorWithMaskSpinButtonUIElement.CanSpin(System.Windows.Forms.ScrollButton direction) + 0x47 bytes Infragistics2.Win.v8.1.dll!Infragistics.Win.EditorWithMaskSpinButtonUIElement.PositionChildElements() + 0x1a7 bytes Infragistics2.Win.v8.1.dll!Infragistics.Win.UIElement.VerifyChildElements(Infragistics.Win.ControlUIElementBase controlElement = {Infragistics.Win.UltraWinGrid.UltraGridUIElement}, bool recursive = true) + 0x51 bytes Infragistics2.Win.v8.1.dll!Infragistics.Win.UIElement.VerifyChildElements(Infragistics.Win.ControlUIElementBase controlElement = {Infragistics.Win.UltraWinGrid.UltraGridUIElement}, bool recursive = true) + 0x9a bytes Infragistics2.Win.v8.1.dll!Infragistics.Win.UIElement.VerifyChildElements(bool recursive) + 0x30 bytes Infragistics2.Win.v8.1.dll!Infragistics.Win.UIElement.VerifyChildElements() + 0xa bytes Infragistics2.Win.v8.1.dll!Infragistics.Win.UltraWinMaskedEdit.EditInfo.ScrollDisplayCharIntoView(int index) + 0x86 bytes Infragistics2.Win.v8.1.dll!Infragistics.Win.UltraWinMaskedEdit.EditInfo.CaretPosition.set(int value) + 0x42 bytes Infragistics2.Win.v8.1.dll!Infragistics.Win.UltraWinMaskedEdit.EditInfo.Delete(bool emulateDeleteKey) + 0x173 bytes Infragistics2.Win.v8.1.dll!Infragistics.Win.UltraWinMaskedEdit.EditInfo.PerformAction(Infragistics.Win.UltraWinMaskedEdit.MaskedEditAction actionCode, bool shift, bool control) + 0x633 bytes Infragistics2.Win.v8.1.dll!Infragistics.Win.EditorWithMask.OnOwnerKeyDown(System.Windows.Forms.KeyEventArgs e = {KeyData = RButton | MButton | Back | Space}) + 0x128 bytes Infragistics2.Win.v8.1.dll!Infragistics.Win.EmbeddableEditorBase.ProcessOwnerKeyDown(object sender, System.Windows.Forms.KeyEventArgs e) + 0xc bytes Infragistics2.Win.v8.1.dll!Infragistics.Win.EmbeddableEditorOwnerBase.RaiseKeyDown(System.Windows.Forms.KeyEventArgs e) + 0x17 bytes Infragistics2.Win.UltraWinGrid.v8.1.dll!Infragistics.Win.UltraWinGrid.UltraGrid.ForwardKeyToEditorHelper(System.Windows.Forms.KeyEventArgs e = {KeyData = RButton | MButton | Back | Space}) + 0xd2 bytes Infragistics2.Win.UltraWinGrid.v8.1.dll!Infragistics.Win.UltraWinGrid.UltraGridUIElement.ProcessKeyDown(System.Windows.Forms.KeyEventArgs e = {KeyData = RButton | MButton | Back | Space}) + 0x75 bytes Infragistics2.Win.v8.1.dll!Infragistics.Win.Utilities.ProcessEvent(System.Windows.Forms.Control control = {Infragistics.Win.UltraWinGrid.DKUltraGrid}, Infragistics.Win.ControlUIElementBase.ProcessEvent eventToProcess = KeyDown, System.EventArgs e = {KeyData = RButton | MButton | Back | Space}) + 0x239 bytes Infragistics2.Win.v8.1.dll!Infragistics.Win.UltraControlBase.OnKeyDown(System.Windows.Forms.KeyEventArgs e) + 0x30 bytes System.Windows.Forms.dll!System.Windows.Forms.Control.ProcessKeyEventArgs(ref System.Windows.Forms.Message m = {msg=0x100 (WM_KEYDOWN) hwnd=0x90bac wparam=0x2e lparam=0x1530001 result=0x0}) + 0x4bc bytes System.Windows.Forms.dll!System.Windows.Forms.Control.ProcessKeyMessage(ref System.Windows.Forms.Message m) + 0x31 bytes System.Windows.Forms.dll!System.Windows.Forms.Control.WmKeyChar(ref System.Windows.Forms.Message m = {msg=0x100 (WM_KEYDOWN) hwnd=0x90bac wparam=0x2e lparam=0x1530001 result=0x0}) + 0x12 bytes System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) + 0x3ee bytes System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) + 0xd bytes System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0x36 bytes System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg = 256, System.IntPtr wparam, System.IntPtr lparam) + 0x5a bytes System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DefWndProc(ref System.Windows.Forms.Message m = {msg=0x100 (WM_KEYDOWN) hwnd=0x90bac wparam=0x2e lparam=0x1530001 result=0x0}) + 0xcc bytes System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0x5 bytes Infragistics2.Win.v8.1.dll!Infragistics.Win.EditorWithMask.AccessibleTextManager.AccessibleTextSubclasser.WndProc(ref System.Windows.Forms.Message msg) + 0x43 bytes System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg = 256, System.IntPtr wparam, System.IntPtr lparam) + 0x5a bytes System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DefWndProc(ref System.Windows.Forms.Message m = {msg=0x100 (WM_KEYDOWN) hwnd=0x90bac wparam=0x2e lparam=0x1530001 result=0x0}) + 0xcc bytes System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0x5 bytes Infragistics2.Win.v8.1.dll!Infragistics.Win.FormattedLinkLabel.FormattedLinkEditor.AccessibleTextManager.AccessibleTextSubclasser.WndProc(ref System.Windows.Forms.Message msg) + 0x3d bytes System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg = 256, System.IntPtr wparam, System.IntPtr lparam) + 0x5a bytes System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DefWndProc(ref System.Windows.Forms.Message m = {msg=0x100 (WM_KEYDOWN) hwnd=0x90bac wparam=0x2e lparam=0x1530001 result=0x0}) + 0xcc bytes System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0x5 bytes Infragistics2.Win.v8.1.dll!Infragistics.Win.FormattedLinkLabel.IMENativeWindowManager.IMENativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0x15 bytes System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg = 256, System.IntPtr wparam, System.IntPtr lparam) + 0x57 bytes [Native to Managed Transition] [Managed to Native Transition] System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(int dwComponentID, int reason = -1, int pvLoopData = 0) + 0x2f1 bytes System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason = -1, System.Windows.Forms.ApplicationContext context = {System.Windows.Forms.ApplicationContext}) + 0x17d bytes System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) + 0x53 bytes System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm) + 0x2e bytes > MyApp.exe!DKHost.DKS.Main(string[ args = {Dimensions:[0]}) Line 40 + 0x1a bytes C# [Native to Managed Transition] [Managed to Native Transition] mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[ args) + 0x39 bytes Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() + 0x2b bytes mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) + 0x3b bytes mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x81 bytes mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x40 bytes
I don't know how avoid this behavior, could you help me to find a solution?
Cheers.
I think it might have something to do with databinding.. if I make sure the spinbuttons are enabled only after the form is visible, and turn them off before it closes it seems to work without errors:
private void TaskEditor_VisibleChanged(object sender, EventArgs e)
{
if (this.Visible)
if (budgetHoursUltraMaskedEdit.SpinButtonDisplayStyle != SpinButtonDisplayStyle.OnRight)
budgetHoursUltraMaskedEdit.SpinButtonDisplayStyle =
SpinButtonDisplayStyle.OnRight;
if (maximumHoursUltraMaskedEdit.SpinButtonDisplayStyle != SpinButtonDisplayStyle.OnRight)
maximumHoursUltraMaskedEdit.SpinButtonDisplayStyle =
if (warningHoursUltraNumericEditor.SpinButtonDisplayStyle != Infragistics.Win.ButtonDisplayStyle.Always)
warningHoursUltraNumericEditor.SpinButtonDisplayStyle = Infragistics.Win.
ButtonDisplayStyle.Always;
}
else
if (budgetHoursUltraMaskedEdit.SpinButtonDisplayStyle != SpinButtonDisplayStyle.None)
SpinButtonDisplayStyle.None;
if (maximumHoursUltraMaskedEdit.SpinButtonDisplayStyle != SpinButtonDisplayStyle.None)
if (warningHoursUltraNumericEditor.SpinButtonDisplayStyle != Infragistics.Win.ButtonDisplayStyle.Never)
ButtonDisplayStyle.Never;
You still definitely shouldn't have to do something like this simply to prevent the controls from throwing an exception internally if you're not performing any invalid behavior. How are you binding the controls? What is the DataType and the Value when the exception is being thrown?
I'm binding through a BindingSource of List<myobject>
It's a System.Nullable<decimal> and I think the value is null when the exception is thrown.I notice I get a couple more of the same exceptions after the form loads and I click on the spin buttons by the blank control. The numbers populate in the control, then further clicks on the spin buttons don't cause anymore exceptions (presumably because there is a number in there now).
I just tried putting together a simple sample based on what you've said and I can't reproduce the error, either when the form loads or by deleting any text that the control has. Does this sample reproduce the issue on your end? If not, can you alter the sample so that it does illustrate the error?
I also realized that I never answered part of your original question, which is how to prevent the user from editing except when using the spin buttons. The best way I can think of is to use the KeyPress event and mark the Handled property to True.
Matt, some confusion here.. I'm not the original poster.. I did upgrade to the latest controls as you suggested. The project you sent me was for v8.1. When I upgraded your project to 9.1.20091.2039 (only thing I changed was the assembly references), I did indeed get the exception using the spin buttons:
A first chance exception of type 'System.Exception' occurred in Infragistics2.Win.v9.1.dllA first chance exception of type 'System.Exception' occurred in Infragistics2.Win.v9.1.dllA first chance exception of type 'System.Exception' occurred in Infragistics2.Win.v9.1.dllA first chance exception of type 'System.InvalidCastException' occurred in mscorlib.dllA first chance exception of type 'System.Exception' occurred in Infragistics2.Win.v9.1.dllA first chance exception of type 'System.Exception' occurred in Infragistics2.Win.v9.1.dllA first chance exception of type 'System.Exception' occurred in Infragistics2.Win.v9.1.dllA first chance exception of type 'System.InvalidCastException' occurred in mscorlib.dll
Thanks I was wondering about that since the first form load seemed to take the longest. Unfortunately, NGen'ing the app isn't possible since it requires administrator permissions on the local PC and I am using ClickOnce. My understanding is it does a separate install per user so I couldn't even have an admin go in and NGen the assemblies. I'll play around a bit and post a new thread if I come up with anything good.
Part of that lag could certainly be related to some exceptions that are handled internally, but another source of lag could be that when the form first loads, .NET needs to JIT compile each of the Infragistics assemblies, which could lead to some delay. One way to test if this is the case is to create a new parent form with no Infragistics controls in it, then have a button that opens your form that does have the controls in it. If there is a delay the first time you show the child form and not the second time, then you could likely assume that most of it comes from the JITing of the assemblies (and subsequently loading them into memory). You can cut down on this by running ngen on the Infragistics assemblies.
Matt, thanks for following up on this. I know the code will run but I was working my way through your postings on speeding up my controls as I am having trouble with a short lag the first time my form opens. One of your reccomendations was to set it to break on all errors and try to get rid of any exceptions.
Sorry about the confusion there, I guess that the point is moot about preventing the user from editing directly.
Regarding the first chance exceptions, these are only hit because you have the Visual Studio debugger set to break on all exceptions, but these exceptions are handled within the Infragistics code and so shouldn't really be affecting your application. I ran the application with the debugger set to break on all exceptions and the only exception I got was the "Section is empty" exception at this point, but looking at the code it seems like in this particular case we should be able to prevent this exception from being thrown internally. I've forwarded this thread to Developer Support so that it can be looked into.
Update: I commented out your datafilter code and I still get the exception.