|
-
May 1st, 2007, 08:21 AM
#1
Thread Starter
Lively Member
[RESOLVED] listview, treeview icons missing
Hi,
I have a user control that has a treeview. I have linked the treeview to an imagelist and set the imageindex of the nodes to images from the imagelist. They all appear correctly at design time.
I also have a separate form that has a listview that is also linked to an imagelist (Tried linking to smallIcon and largeIcon). I have manually added listview items and set the imageIndex (and tried imagekey) of the items to icons available in imagelist. These appear correctly at deisgn time. In my main sub i have a call to .DoEvents
Code:
Application.EnableVisualStyles()
Application.DoEvents()
Application.Run(frmMainInstance)
I have also tried to add icons programmatically,
Code:
Me.list.Items(0).ImageKey = 0
I have tried all 5 listview view modes.
When I run the app no icons appear in treeview or listview. I can't think of what I'm doing wrong. Any ideas?
-
May 1st, 2007, 08:55 AM
#2
Fanatic Member
Re: listview, treeview icons missing
Well in the Listview, it uses two different ImageLists - Large and Small. It depends on your view. Make sure you're matching the right views - Detail/Report to Small, the others to Large.
It's not ImageKey that you use, it's ImageIndex. ImageKey would be for Images you added with a text key like "image1" or "foldericon".
so this would be better:
vb Code:
Me.ListView1.LargeImageList = Me.MyLargeImageList 'change to SmallImageList for report view
Me.ListView1.Item(0).ImageIndex = 0 'or 1, or 2, or 3, depending on what image you want.
Warren Ayen
Senior C# Developer
DLS Software Studios ( http://www.dlssoftwarestudios.com/)
I use Microsoft Visual Studio 2005, 2008, working with Visual Basic and Visual C#
Hey! If you like my post, or I solve your issue, please Rate Me!
-
May 1st, 2007, 09:02 AM
#3
Re: listview, treeview icons missing
If you comment out the code
Application.EnableVisualStyles()
Application.DoEvents()
do they show up every time?
I am guessing you are using .NET 1.1 (VB 2003) because I remember that was a bug in the framework with Visual Styles and the icons..
I thought the call to doevents was supposed to fix it..
but I think I remember reading that you should have
Application.EnableVisualStyles()
Application.DoEvents()
before ANY other code in you your apps entry point (generally sub main)
So do you have any code before your call to EnableVisualStyles?
-
May 2nd, 2007, 06:22 AM
#4
Thread Starter
Lively Member
Re: listview, treeview icons missing
 Originally Posted by kleinma
If you comment out the code
Application.EnableVisualStyles()
Application.DoEvents()
do they show up every time?
I am guessing you are using .NET 1.1 (VB 2003) because I remember that was a bug in the framework with Visual Styles and the icons..
I thought the call to doevents was supposed to fix it..
but I think I remember reading that you should have
Application.EnableVisualStyles()
Application.DoEvents()
before ANY other code in you your apps entry point (generally sub main)
So do you have any code before your call to EnableVisualStyles?
I disabled,
Code:
Application.EnableVisualStyles()
Application.DoEvents()
and icons appear! Thanks for the suggestion. I'm running 2005 .net 2 and only have 3 lines of code in my main sub so far,
Code:
Sub Main()
Application.EnableVisualStyles()
Application.DoEvents()
Application.Run(frmMainInstance)
End Sub
Any idea what could be causing this problem? I'm aware of the earlier defect with EnableVisualStyles / DoEvents and also thought it had been resolved.
-
May 2nd, 2007, 10:02 AM
#5
Re: listview, treeview icons missing
if you are running .NET 2005, then Visual Styles are built in and supported from the get go.
There is no need to call EnabledVisualStyles in 2005 if in the My Project configuration you have "Enable Application Framework" checked, and also "Enabled XP visual styles" checked (which they are by default when you start a new win forms project).
-
May 2nd, 2007, 10:10 AM
#6
Thread Starter
Lively Member
Re: listview, treeview icons missing
Thanks for your time,
if you enable application framework then you are required to specify a form as startup object, before you can go on and edit application framework properties . I don't want to do this as I am starting an instance of a form.
-
May 2nd, 2007, 10:12 AM
#7
Re: listview, treeview icons missing
any specific reason?
Even with a form specified as the startup form, there is still code that can run before that form ever loads...
You can click on the ApplicationEvents button, and write code to handle the startup event of your app. This is basically equal to a Sub Main, and you can set e.cancel to true in it to prevent the main form from ever loading.
-
May 3rd, 2007, 03:25 AM
#8
Thread Starter
Lively Member
Re: listview, treeview icons missing
Thanks, that's a handy tip.
I just noticed however that my project may be 1.0 and not 2.0 as I suspected. This is odd as I have created this new project using v2005 and all my other previously created projects report using 2.0 .net framework. I noticed this when I referenced this project from another one and in the references section the version showed as 1.0.0.0. Looking at the assembly version of this project. Not sure how this has happened, but at least it explains why DoEvents didn't resolve the original problem.
-
May 3rd, 2007, 03:31 AM
#9
Re: [RESOLVED] listview, treeview icons missing
The fact that you are using version 1.0.0.0 of your application is no reflection on what .NET version it uses. You could be using version 10.2.23.15 of your app and it would still use version 2.0 of the .NET Framework.
-
May 4th, 2007, 06:54 AM
#10
Thread Starter
Lively Member
Re: [RESOLVED] listview, treeview icons missing
Now I'm confused,
and although I could do the clever little hack that kleinma suggested, i would prefer to understand why icons don't appear if I uncomment,
Code:
Application.EnableVisualStyles()
Application.DoEvents()
and i am using .NET 2.
In project references all system .dlls references point to ...\Framework\v2.0.50727\.... so I presume this tells me that it is using .NET 2.0. I also presume that visual studio uses the latest version of the framework installed by default?
Thanks
-
May 4th, 2007, 08:52 AM
#11
Re: [RESOLVED] listview, treeview icons missing
If you are using Visual Studio 2005, then you are targeting the .NET 2.0 framework. It is as simple as that.
Visual Studio 2002 = .NET 1.0
Visual Studio 2003 = .NET 1.1
Visual Studio 2005 = .NET 2.0
Also using the Application Framework and having it do visual styles automatically is in no way a hack. If anything the enablevisualstyles method is a hack because it has never worked 100% correctly.
-
May 4th, 2007, 08:44 PM
#12
Re: [RESOLVED] listview, treeview icons missing
There's no reason to use a Main method as an entry point in VB 2005. You should enable the Application Framework and Visual Styles via the Application tab of the project properties. Both those options are checked by default. If there is any other work that needs doing that you would previously have done in a main method then you should handle the application's Startup event and do it there.
-
May 8th, 2007, 04:38 AM
#13
Thread Starter
Lively Member
Re: [RESOLVED] listview, treeview icons missing
Thank you both for your help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|