ListView Item can't show Icon

I have programatically and set the ListView item using Visual Effect, but it cannot shown the icon after visual effect being applied.

ListView1.View = View.LargeIcon
ListView1.LargeImageList = imgIcons

ListView1.Items.Add("Item 1", 0)
ListView1.Items.Add("Item 2", 1)

If I didn't using Application.EnableVisualEffects() routine, everything workout normally. But if I code it at Routine, it will not shown out the icons being display.

Please guide me how to do it.



Answer this question

ListView Item can't show Icon

  • chrisjohnson

    There are two problems:

    1. You need to place the Application.DoEvent call after the call to Application.EnableVisualStyles

    2. You should place both these methods in your main method. These calls should the one of the first methods called in your application. But as you can see you are initalizing the components of your form before calling them, this is why you are having problems.

    Do the following:



    Sub Shared Main()

    Application.EnableVisualStyles()
    Application.DoEvents()
    Application.Run(new MainForm())
    End Sub

     

    Replace MainForm with the name of your form.



  • Mougenot

    Hi

    I am also experiencing this problem and I'm using .NET 2.0. Using the DoEvents makes no difference. I have converted a program from .NET 1.1 into .NET 2.0. If I create a new application I do not get the problem but when I use my older program than the listview control does not show the icons. If I remove the EnableVisualStyle then the icons appear but any listitems that have had text changed to bold or the background color changed this does not show correctly. If you create a new project in 2.0 and do not have the Enable Application Framework checked I can then reproduce the same error. Is there anything else I can try

    Regards - Paul

     

     


  • bc020400363

    Hi Paul,

        Actually I am using .NET 1.1 to develop my application. Actually the problems that I have met is the EnableVisualEffect() events to enable XP visualization.

        Since I was using VB.NET to do it, it performs well as it.

        This was the actual coding for the ListView to EnableVisualEffect() and DoEvents()

    Public Sub New()

        MyBase.New()

        Application.EnableVisualStyles()
        Application.DoEvents()

        'This call is required by the Windows Form Designer.
        InitializeComponent()
        'Add any initialization after the InitializeComponent() call
    End Sub


  • Venkat Sathyamurthy

    If I read this correctly:

    When you use Application.EnableVisualStyles() your icons within the ListView aren't displayed, however when you remove the call Application.EnableVisualStyles() they are

    If this is the case, then I suspect that you are using .NET 1.1, and if so this is a known bug.

    To fix this, simply place a call to Application.DoEvents() directly after your call to Application.EnableVisualStyles().



  • Rebecca Karma

    Since i was using .NET 1.1, I just place a call to the routine as following:

    Public Sub New()
    MyBase.New()
    'This call is required by the Windows Form Designer.
    InitializeComponent()
    Application.DoEvents()
    Application.EnableVisualStyles()
    'Add any initialization after the InitializeComponent() call

    End Sub

    But it seems that there is still can't shown the icon as well after DoEvents() routine being called. Beside I put there, is there any method we can just simly let the icon shown at the listview control. But anywhere, thank you for your advice. 


  • amal02

    Thanks mike. It would much more appreciate for me.
  • ListView Item can't show Icon