Newbie: Porblem with ListView...
-
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"
-
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"
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 ?
-
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 ?
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"
-
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"
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