How do I add items and subitems to a programtically created listview?
Posted on 2007-08-10
USING: VB.Net 2005 compact framework 2
I have a tab called tabProj and a page in that tab named tpTally. The code reads a database and adds textboxes and one listview depending on the database. The listview name is lvTree, that never changes but the number of columns changes based on the database.
There is a direct correlation between the textboxes and the subitems. When a button is pressed I want it to scan all textboxes in tpTally and then add the text in each textbox as a subitem in lvTree. The item will just be a counter.
For example the first time the item will be 1 (in other words the count of items in the listview + 1) and the subitems will be the value in each textbox.
I have the code working up to the point of adding all of the column names correctly. I just don't know how to add subitems to a listview that will be created at runtime.
Here is what I have and I don't even know if I am on the right track yet:
button click code: (not working)
'add tree data to listview
Dim tabpagADD As TabPage
Dim lsi As New ListViewItem
Dim lv As ListView
For Each tabpagADD In tabProj.TabPages
If tabpagADD.Name = "tpTally" Then
For Each ctrlList As Control In tabpagADD.Controls
If TypeOf ctrlList Is ListView And ctrlList.Name = "lvTree" Then
For Each ctrlADD As Control In tabpagADD.Controls
If TypeOf ctrlADD Is TextBox And ctrlADD.Visible = True Then
'add items and subitems here
Any and all help is appreciated