I am using the ListView in Details mode; and I would like to create a listviewitem regardless of whether I am adding to the ultraListView or not. It seems this is not possible since the only way I have found to creat a new listviewitem is to call the Add method of the ultraListView control.
1. Is there a way to create a listviewitem (object) without calling the Add method?
If there is a way, that would be great; since not all listviewitems I will create should automatically be displayed in the ultraListView. Some items are stored in another generic-list for later use. For example, when the user clicks on a specific button, I would append the ultralistviewitems to the current ultraListView control. My current means of implementation is simply to create the new item with the Add method, populate its columns, and then delete it from the ultraListView. However I am afraid this has a major performance impact to my client application as I may be required to process 100s if not 1000s of such routines per second. My app performance atm - at about 5Hz, my TaskManager reports a CPU usage of about 20%; at about 100 Hz, we looking at about 60%; and at 1 KHZ, we close to about 100% CPU usage (my machine 2.2GHz/2GB ram).
2. I have also tried to create a listviewitem (object) during InitializeComponent to initialize my global variable. After the global variable was initialized (with the add method), I would immediately remove the item from the ultraListView. Then when the time came to use an ultraListViewItem, I would clone my original global variable, and work with that instead. However I keep getting an error saying:
"The SubItems collection cannot be accessed when the parent UltraListViewItem is not associated with an UltraListView control"
Which leaves me with my current (and only) option - which is to Add the item, work with it, and then Remove it if it is not immediately needed.
Any ideas?
thanks,-kel-
The UltraListViewItem class exposes a constructor overload that takes the item's value, and an object array which defines the values for each of its sub items. You can use this overload to assign initial values to each of the sub-items, before the item is associated with a control (thus avoiding the exception). When the item is added to the control's Items collection, the associated sub-items will pick up the values you specified in that array.
Using the Add method to add a relatively large number of items can impact performance; the Items collection exposes an AddRange method which you can use to add multiple items in one atomic operation. UltraListView out-performs the standard .NET ListView control in this scenario.
If the above mentioned approaches do not address the performance issue, you should log a bug report so that we can investigate what is causing the problem.
thanks mstief,
now i remember where i saw that from. I must have tried creating an UltraListViewItem and assigning the subitems afterwards - which would throw exceptions.
anyhow, I'm afraid I have moved on to using a DataSource and binding a gridview to it; since performance was a major issue with the ultralistview to begin with.
anyways thanks for your trouble. i've marked your post as the answer.
-kel-
To answer your first question, is yes you can create a listview item without using the add method on the ultralistview. Here is an example.
UltraListViewItem item = new UltraListViewItem ( "mstief", new UltraListViewSubItem[ { new UltraListViewSubItem("Guber",null), new UltraListViewSubItem("Yes", null)}, null );
A quick way to see how this gets done is add an item using the designer and then go to the designer code to see how Infragistics created the list view item.Hope this helps some.