Solved

VB.Net: Multicolumn Listview

Posted on 2012-04-06
4
539 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
ID: 37816638
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
ID: 37816641
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
ID: 37817546
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
ID: 37817823
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 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