Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Bug in ListView.Items.Insert(int,ListViewItem)?

Bug in ListView.Items.Insert(int,ListViewItem)?

Scheduled Pinned Locked Moved .NET (Core and Framework)
helpcomquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AndrewVos
    wrote on last edited by
    #1

    I seem to have found a bug in ListView.Items.Insert(int,ListViewItem). Could someone please try reproduce this? Maybe I could get a bug report submitted. (Problem seems to occur on 2.0 and 3.5) Steps to Reproduce: 1. Start a new project 2. Add a ListView with five items in it. 3. Label them 1 to 5 so we can see what happens. 4. Add a Button. 5. Add the following code to Button.Click: ListViewItem item4 = this.listView1.Items[3]; item4.Remove(); this.listView1.Items.Insert(0, item4); The items should be arranged like this: 4 - 1 - 2 - 3 - 5 Instead we see this: 1 - 2 - 3 - 5 - 4 Workaround: I have found if we switch to View.Details before doing the remove/insert then everything works fine. Replace the code in Button.Click with this: ListViewItem item4 = this.listView1.Items[3]; View oldView = this.listView1.View; this.listView1.BeginUpdate(); this.listView1.View = View.Details; item4.Remove(); this.listView1.Items.Insert(0, item4); this.listView1.View = oldView; this.listView1.EndUpdate();


    www.wickedorange.com www.andrewvos.com

    R U 2 Replies Last reply
    0
    • A AndrewVos

      I seem to have found a bug in ListView.Items.Insert(int,ListViewItem). Could someone please try reproduce this? Maybe I could get a bug report submitted. (Problem seems to occur on 2.0 and 3.5) Steps to Reproduce: 1. Start a new project 2. Add a ListView with five items in it. 3. Label them 1 to 5 so we can see what happens. 4. Add a Button. 5. Add the following code to Button.Click: ListViewItem item4 = this.listView1.Items[3]; item4.Remove(); this.listView1.Items.Insert(0, item4); The items should be arranged like this: 4 - 1 - 2 - 3 - 5 Instead we see this: 1 - 2 - 3 - 5 - 4 Workaround: I have found if we switch to View.Details before doing the remove/insert then everything works fine. Replace the code in Button.Click with this: ListViewItem item4 = this.listView1.Items[3]; View oldView = this.listView1.View; this.listView1.BeginUpdate(); this.listView1.View = View.Details; item4.Remove(); this.listView1.Items.Insert(0, item4); this.listView1.View = oldView; this.listView1.EndUpdate();


      www.wickedorange.com www.andrewvos.com

      R Offline
      R Offline
      Rob Smiley
      wrote on last edited by
      #2

      Does the same thing here:confused:

      "An eye for an eye only ends up making the whole world blind"

      A 1 Reply Last reply
      0
      • R Rob Smiley

        Does the same thing here:confused:

        "An eye for an eye only ends up making the whole world blind"

        A Offline
        A Offline
        AndrewVos
        wrote on last edited by
        #3

        Thanks for checking it out. What version of .NET?


        www.wickedorange.com www.andrewvos.com

        R 1 Reply Last reply
        0
        • A AndrewVos

          Thanks for checking it out. What version of .NET?


          www.wickedorange.com www.andrewvos.com

          R Offline
          R Offline
          Rob Smiley
          wrote on last edited by
          #4

          that was using .net 2

          "An eye for an eye only ends up making the whole world blind"

          1 Reply Last reply
          0
          • A AndrewVos

            I seem to have found a bug in ListView.Items.Insert(int,ListViewItem). Could someone please try reproduce this? Maybe I could get a bug report submitted. (Problem seems to occur on 2.0 and 3.5) Steps to Reproduce: 1. Start a new project 2. Add a ListView with five items in it. 3. Label them 1 to 5 so we can see what happens. 4. Add a Button. 5. Add the following code to Button.Click: ListViewItem item4 = this.listView1.Items[3]; item4.Remove(); this.listView1.Items.Insert(0, item4); The items should be arranged like this: 4 - 1 - 2 - 3 - 5 Instead we see this: 1 - 2 - 3 - 5 - 4 Workaround: I have found if we switch to View.Details before doing the remove/insert then everything works fine. Replace the code in Button.Click with this: ListViewItem item4 = this.listView1.Items[3]; View oldView = this.listView1.View; this.listView1.BeginUpdate(); this.listView1.View = View.Details; item4.Remove(); this.listView1.Items.Insert(0, item4); this.listView1.View = oldView; this.listView1.EndUpdate();


            www.wickedorange.com www.andrewvos.com

            U Offline
            U Offline
            User 4210069
            wrote on last edited by
            #5

            Works, thanks a lot. I am using VS 2010 prof. and had the same problem. Using above code fixed it.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups