I'm using Krypton 4.4 and .NET 4.0 and was experiencing the same behavior, but it dealt with the KryptonComboBox. Like matao, the error appeared to not be passing through my code at all, but rather through the Krypton framework and .NET itself.
After some investigation into the Krypton source code and looking at the stack trace when this error was thrown, I noticed that the KryptonComboBox (or a part of the Krypton framework) was attaching to the Microsoft.Win32.SystemEvents.OnUserPreferenceChanged event which got me thinking. Perhaps the reason this wasn't going through my code was that this event was being triggered from the OS at some point. It still didn't explain why the error was being thrown, but I started thinking about this problem in a different manner.
Now, whenever this error happened, it always traversed through the KryptonComboBox, but it wasn't consistent in any manner. It was actually very difficult to invoke. However, because of the OnUserPreferenceChanged event firing, I started looking at things like Global Policy changes or something that would trigger that event. Through some luck I noticed that if I had my WinForms app running and launched Internet Explorer, I could reliably get this exception to pop up. Don't ask me why this happens, but apparently launching IE somehow fires the OnUserPreferenceChanged event.
Now that I had a reliable way to trigger the exception, I started looking at KryptonComboBox instances in my code and commenting out entire modules to see if I could get this exception to come back. Eventually, I found the error and it turned out to be an error in how code in my WinForms app was being wired up. Specifically, here is the error:
KryptonComboBox detailView = new KryptonComboBox();
detailView.Sorted = true;
detailView.Text = "View";
detailView.Items.Add(new KryptonListItem("Details", "Detail View"));
detailView.Items.Add(new KryptonListItem("List", "List"));
detailView.Items.Add(new KryptonListItem("Tile", "Tiles"));
ToolStripMenuItem mItem = new ToolStripMenuItem();
mItem.Tag = detailView;
mItem.Text = detailView.Text;
mItem.Click += new EventHandler(contextItem_Click);
My guess is that because detailView
is not wired up to the Control pipeline the, the Krypton framework has some issues attempting to update the Palette of the KryptonCombBox control.
One weird nuance that I noticed is that after the first exception was thrown within the Krypton framework, it appeared to corrupt the Graphics object. Subsequent calls to update the Palette (to switch colors of the Krypton controls), the error would always throw but through a different area in the call stack (always initiated from somewhere within my source code).
Matao, I'm not sure this answers your question, but I believe you may have some issue with how you're wiring up your Controls within the DataGridView. Perhaps you're associating a control with the Tag property on something within the DataGridView?
I hope this gives you some insight into your problem.
* Edit *
Per Matao's question, I fixed the problem by removing the code that was adding the KryptonComboBox
to the Tag property of the ToolStripMenuItem
. Instead, to get the functionality I wanted, I simply added some additional ToolStripMenuItems
to the DropDownItems
property of mItem
.
I would look into your source code for any dynamically created controls that aren't being added to the Control pipeline.