Converting VB ListBox to ListView in VB.net

G

Guest

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

Michelle

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
 
G

Guest

This helps greatly.

After the list is built is tthere a way to select the first row. Like the
old ...Index=0?
 
M

Michelle

Yup, you should be able to use something like this:

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


Take Care!
Michelle
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top