Solved

VB.Net: Multicolumn Listview

Posted on 2012-04-06
4
555 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

623 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