Hey guys,
Long time no see, thought I'd post this up really quickly as I found it useful.
I had a problem with creating a custom TreeView, I was coming across an issue where even though I was checking to see if the control was in DesignMode, it would execute the code at design time anyway.
For example:
This creates a node at design time, and seems to be a bug when inheriting some controls. To over come this I found you can use LicenseManager.UsageMode in System.ComponentModel to check the state instead (LicenseUsageMode.DesignTime). Because it is ignoring DesignMode = False, we end up with duplicate nodes at runtime.
Here is the working code:
This prevents the code executing at design time, and also prevents duplicate 'phantom' nodes as well.
All credit goes to Keith Barrow, with his notes on auto-loading data. Provided the fix I needed.
Thanks for reading!
Eprouvez
P.S - I'll release my custom TreeView component for testing soon, if anyone is interested let me know here!
Long time no see, thought I'd post this up really quickly as I found it useful.
I had a problem with creating a custom TreeView, I was coming across an issue where even though I was checking to see if the control was in DesignMode, it would execute the code at design time anyway.
For example:
Code
Public Class Test
Inherits TreeView
Public Sub New()
Nodes.Clear()
If Not DesignMode Then
Nodes.Add(New TreeNode("TEST NODE"))
End If
End Sub
End ClassThis creates a node at design time, and seems to be a bug when inheriting some controls. To over come this I found you can use LicenseManager.UsageMode in System.ComponentModel to check the state instead (LicenseUsageMode.DesignTime). Because it is ignoring DesignMode = False, we end up with duplicate nodes at runtime.
Here is the working code:
Code
'Imports System.ComponentModel
Public Class Test
Inherits TreeView
Public Sub New()
Nodes.Clear()
If Not System.ComponentModel.LicenseManager.UsageMode = System.ComponentModel.LicenseUsageMode.Designtime Then
Nodes.Add(New TreeNode("TEST NODE"))
End If
End Sub
End ClassThis prevents the code executing at design time, and also prevents duplicate 'phantom' nodes as well.
All credit goes to Keith Barrow, with his notes on auto-loading data. Provided the fix I needed.
Thanks for reading!
Eprouvez
P.S - I'll release my custom TreeView component for testing soon, if anyone is interested let me know here!

