Hi,
I'm gonna add an item to a ListView in VirtualMode.
Below is my C# code to do that :
The Exception :Code:listView1.VirtualMode = true; listView1.VirtualListSize = query.Count(); foreach (var item in query) { i++; string tableNumber = item.TableNumber.HasValue ? item.TableNumber.Value.ToString() : ""; ListViewItem newItem = new ListViewItem(new string[] { i.ToString(), item.FactorType.ToString(), item.FactorNumber.ToString(), tableNumber.ToString(), item.Price.ToString(), DateTime.Now.ToString() }); newItem.Font = new Font("Tahoma", 12); newItem.Name = "Item" + i.ToString(); listView1.Items.Add(newItem);//Exception } void listView1_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e) { e.Item = new ListViewItem(e.ItemIndex.ToString()); }
Would you please guide me ?Code:When the ListView is in virtual mode, you cannot add items to the ListView items collection. Use the VirtualListSize property instead to change the size of the ListView items collection.
Thanks.




Reply With Quote
