Solved

VB.Net: Multicolumn Listview

Posted on 2012-04-06
4
527 Views
Last Modified: 2012-04-08
Hi Experts,

How can i add values to a multicolumn listview and read data from a multicolumn listview?

Thanks in advance.
0
Comment
Question by:baabaa_nl
  • 3
4 Comments
 
LVL 17

Expert Comment

by:nepaluz
Comment Utility
You get the values for the columns fromthe subitems, e.g
Dim LView As New ListView
LVItem.SubItems(0).Text = "First Column"
LVItem.SubItems(1).Text = "Second Column"

Open in new window

Or you can retrieve all the items in a listview and iterate over them
Dim LView As New ListView
For Each x As ListViewItem In LView.Items
    Dim First = x.SubItems(0)
    Dim Second = x.SubItems(1)
Next

Open in new window

0
 
LVL 17

Expert Comment

by:nepaluz
Comment Utility
Use the same to set values, e.g
Dim LView As New ListView
For Each x As ListViewItem In LView.Items
    x.SubItems(0).Text = "Set First Column"
    x.SubItems(1).Text = "Set Second Column"
Next

Open in new window

0
 

Author Comment

by:baabaa_nl
Comment Utility
Hi Nepaluz,

I am trying to add two columns, and has about 5 rows. The data is fed from the database using an OledbDataReader.

The first column will have ID number and the second column will have names, could you please show me the code to achieve that grammatically.

Thanks in advance.
0
 
LVL 17

Accepted Solution

by:
nepaluz earned 500 total points
Comment Utility
I have tried to mimic your returned datatable with a manual one, here goes....
Dim LVTable As DataTable = New DataTable("LVTbl")
LVTable.Columns.AddRange({New DataColumn With {.ColumnName = "FirstCol"}, New DataColumn With {.ColumnName = "SecondCol"}})
LVTable.Rows.Add({"First", "First Value"})
LVTable.Rows.Add({"Second", "Second Value"})
LVTable.Rows.Add({"Third", "Third Value"})
Dim LView As New ListView
'hereswhere youadd theitems
For Each x As DataRow In LVTable.Rows
    Dim LVItem As New ListViewItem
    LVItem.SubItems(0).Text = x.Item(0)
    LVItem.SubItems(1).Text = x.Item(1)
    LView.Items.Add(LVItem)
Next

Open in new window

0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now