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. C#
  4. Newbie: Porblem with ListView...

Newbie: Porblem with ListView...

Scheduled Pinned Locked Moved C#
helpdatabasequestionannouncement
4 Posts 2 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.
  • P Offline
    P Offline
    Phillip Hodges
    wrote on last edited by
    #1

    Hello all, I am having a little trouble with a ListView. I am trying to update an item but it isn't doing what it should... To explain: I have a list containing about 20 items. I can find the index location for the item I want to update. I am then removing the old item at the found index location, and then inserting the new item at the same point. It works, but with one problem... It isn't inserting the new item at the correct index position. Instead it is putting it at the bottom of the list... And I can't work out why?? I am viewing the list in 'tile' view. Can anybody help? Thanks in advance, Phil

    "Rules are for the obedience of fools and the guidance of wise men"

    B 1 Reply Last reply
    0
    • P Phillip Hodges

      Hello all, I am having a little trouble with a ListView. I am trying to update an item but it isn't doing what it should... To explain: I have a list containing about 20 items. I can find the index location for the item I want to update. I am then removing the old item at the found index location, and then inserting the new item at the same point. It works, but with one problem... It isn't inserting the new item at the correct index position. Instead it is putting it at the bottom of the list... And I can't work out why?? I am viewing the list in 'tile' view. Can anybody help? Thanks in advance, Phil

      "Rules are for the obedience of fools and the guidance of wise men"

      B Offline
      B Offline
      baerten
      wrote on last edited by
      #2

      Hello, You tried already : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformslistviewlistviewitemcollectionclassinserttopic.asp Creates a new item and inserts it into the collection at the specified index. [C#] public ListViewItem Insert(int, string); that doesn't work? You have some code ?

      P 1 Reply Last reply
      0
      • B baerten

        Hello, You tried already : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformslistviewlistviewitemcollectionclassinserttopic.asp Creates a new item and inserts it into the collection at the specified index. [C#] public ListViewItem Insert(int, string); that doesn't work? You have some code ?

        P Offline
        P Offline
        Phillip Hodges
        wrote on last edited by
        #3

        Thanks for the reply... I can insert the item. It is just not being inserted where I asked it to be... Here is the code: // Find location of original item in listview ListViewItem temp = new ListViewItem(); temp = listView_main.FindItemWithText(item_text, true, 0); int location = temp.Index; // Create listview item ListViewItem lvItem = new ListViewItem(item_text, icon); lvItem.SubItems.Add("Name:" + name + "(" + aka + ")"); lvItem.SubItems.Add("Data:" + data); lvItem.ToolTipText = item.ToString(); lvItem.Group = listView_main.Groups[0]; // Remove old item in listview listView_main.Items.RemoveAt(location); // Add new item to listview listView_main.Items.Insert(location, lvItem); Hope that helps... Phil

        "Rules are for the obedience of fools and the guidance of wise men"

        B 1 Reply Last reply
        0
        • P Phillip Hodges

          Thanks for the reply... I can insert the item. It is just not being inserted where I asked it to be... Here is the code: // Find location of original item in listview ListViewItem temp = new ListViewItem(); temp = listView_main.FindItemWithText(item_text, true, 0); int location = temp.Index; // Create listview item ListViewItem lvItem = new ListViewItem(item_text, icon); lvItem.SubItems.Add("Name:" + name + "(" + aka + ")"); lvItem.SubItems.Add("Data:" + data); lvItem.ToolTipText = item.ToString(); lvItem.Group = listView_main.Groups[0]; // Remove old item in listview listView_main.Items.RemoveAt(location); // Add new item to listview listView_main.Items.Insert(location, lvItem); Hope that helps... Phil

          "Rules are for the obedience of fools and the guidance of wise men"

          B Offline
          B Offline
          baerten
          wrote on last edited by
          #4

          namespace codepro { /// /// Zusammenfassung für Form1. /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.ListView TheList; private System.Windows.Forms.ColumnHeader columnHeader1; private System.Windows.Forms.ColumnHeader columnHeader2; private System.Windows.Forms.Button button1; /// /// Erforderliche Designervariable. /// private System.ComponentModel.Container components = null; public Form1() { // // Erforderlich für die Windows Form-Designerunterstützung // InitializeComponent(); // // TODO: Fügen Sie den Konstruktorcode nach dem Aufruf von InitializeComponent hinzu // } /// /// Die verwendeten Ressourcen bereinigen. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Vom Windows Form-Designer generierter Code /// /// Erforderliche Methode für die Designerunterstützung. /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. /// private void InitializeComponent() { System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(new string[] { "One", "1.2.", "1.3.", "1.4."}, -1); System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem(new string[] { "Two", "2.1.", "2.2.", "2.3."}, -1); System.Windows.Forms.ListViewItem listViewItem3 = new System.Windows.Forms.ListViewI

          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