Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Control crashes when using Windows Classic Theme

Status
Not open for further replies.

ro88o

Programmer
Jun 25, 2005
24
GB
Hi,
I have a control that is using a custom tree view, the problem that I am having is that when using the 'Windows Classic Theme' in XP (i.e. visual styles are turned off) I get the following error:

Visual Styles-related operation resulted in an error because no visual styles is currently active.
************** Exception Text **************
System.InvalidOperationException: Visual Styles-related operation resulted in an error because no visual style is currently active.
at System.Windows.Forms.VisualStyles.VisualStyleRenderer.IsCombinationDefined(String className, Int32 part)
at System.Windows.Forms.VisualStyles.VisualStyleRenderer..ctor(String className, Int32 part, Int32 state)
at System.Windows.Forms.VisualStyles.VisualStyleRenderer..ctor(VisualStyleElement element)
at AdvancedDataGridView.TreeGridView..ctor()
at ServicesTree.InitializeComponent()
at ServicesTree..ctor(Int32 alertIdIn)

I found a peice of code that may have been using visual styles so I put the following if statement around it:
if (VisualStyleInformation.IsSupportedByOS && VisualStyleInformation.IsEnabledByUser)
treeGridView1.EnableHeadersVisualStyles = true;

However this did not solve the problem, I have found one more peice of code that uses visual styles:
internal VisualStyleRenderer rOpen = new VisualStyleRenderer(VisualStyleElement.TreeView.Glyph.Opened);
...but that's a definition so I can't wrap it in an if statement like above.

Does anybody know how I can get round this? Is it even going to be possible for me to use this treeview with visual styles disabled?

Thanks in advance for any help,
Tom
 
What is the code in your main entry point, if I may ask? A lot of times when enabling visual styles, you do so in main. Also, I would check the properties on the tree view (if you're using a custom tree view and as such are inheriting from the supplied tree, check the base properties).

Good Luck!
-Kevin

- "The truth hurts, maybe not as much as jumping on a bicycle with no seat, but it hurts.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top