Discussion:
Converting VB ListBox to ListView in VB.net
(too old to reply)
John Pyle
2005-02-09 19:57:07 UTC
Permalink
I have an application that I am converting to vb,net. I use a list box with
multiple columns that I reference using the "list" function. How do I do this
in vb.net? The list box looks like this:

Col1 Col2 Col3
C11 C21 C31
C12 C22 C23
...

How do I build it?
How do I reference a specific column when a row is selected?
M***@bwalk.com
2005-02-09 21:06:26 UTC
Permalink
Hi John,

A list view will definately work for this. Here's an example of how I
programmically build a list view:

_____________________
lvwQuickView.BeginUpdate()

lvwList1.Columns.Add("Col1", 50, HorizontalAlignment.Left)
lvwList1.Columns.Add("Col2", 75, HorizontalAlignment.Left)
lvwList1.Columns.Add("Col3", 75, HorizontalAlignment.Left)


For Each tmpRecord In myCollection
Dim item As ListViewItem
item = lvwList1.Items.Add(New ListViewItem(New String(2)
{info1, info2, info3}))
item.Tag = tmpRecord
Next

lvwQuickView.EndUpdate()
_____________________


To reference individual columns when a row is selected:

lvwList1.SelectedItems(0).SubItems(0).Text



I hope this helps.

Michelle
John Pyle
2005-02-09 21:31:06 UTC
Permalink
This helps greatly.

After the list is built is tthere a way to select the first row. Like the
old ...Index=0?
Post by M***@bwalk.com
Hi John,
A list view will definately work for this. Here's an example of how I
_____________________
lvwQuickView.BeginUpdate()
lvwList1.Columns.Add("Col1", 50, HorizontalAlignment.Left)
lvwList1.Columns.Add("Col2", 75, HorizontalAlignment.Left)
lvwList1.Columns.Add("Col3", 75, HorizontalAlignment.Left)
For Each tmpRecord In myCollection
Dim item As ListViewItem
item = lvwList1.Items.Add(New ListViewItem(New String(2)
{info1, info2, info3}))
item.Tag = tmpRecord
Next
lvwQuickView.EndUpdate()
_____________________
lvwList1.SelectedItems(0).SubItems(0).Text
I hope this helps.
Michelle
M***@bwalk.com
2005-02-09 21:39:04 UTC
Permalink
Yup, you should be able to use something like this:

lvwList1.Items(0).SubItems(0).Text


Take Care!
Michelle

Continue reading on narkive:
Search results for 'Converting VB ListBox to ListView in VB.net' (Questions and Answers)
3
replies
Help with Visual Basics?
started 2009-01-14 16:25:04 UTC
programming & design
Loading...