Hi,
I am trying to use a VB.NET listview object to display information
from a datatable. I need to have two columns of information but I
don't want the user to be able to select each column individually -
that's why I am attempting to use a listview rather than a datagrid.
I have been reading a lot of postings in this newsgroup concerning
multiple columns in listviews and I have tried to follow all the
advice I have found - but I am still having trouble. I have not been
able to get the second column of information to show up in the
listview.
Here is my code:
Dim tbl As DataTable = New DataTable
Dim col As Integer
Dim row As DataRow
Dim lvi As ListViewItem
tbl.Columns.Add("test")
tbl.Columns.Add("test2")
row = tbl.NewRow
row(0) = "help"
row(1) = "help me"
tbl.Rows.Add(row)
NodeList.BeginUpdate()
For col = 1 To tbl.Columns.Count
'Create a listview column for each dataset column
NodeList.Columns.Add(New ColumnHeader)
Next
row = Nothing
For Each row In tbl.Rows
'Create a listview item for each row in dataset, using text from
col0
lvi = New ListViewItem(CStr(row(0)))
col = 1
Do While col < tbl.Columns.Count - 1
'Append the subsequent columns
lvi.SubItems.Add(row(col))
col += 1
Loop
NodeList.Items.Add(lvi)
Next
Does anyone know what I am doing wrong??
Also, for some reason, I am having trouble with my Visual Studio 2003
program - it doesn't detect/recognize my code or any errors I make
until I compile it - this just started happening yesterday when I
started working with this problem - so I don't know if they are in any
way connected but I thought I would just mention it just in case.
Any advice would be greatly appreciated!!
Joy