Solved

VB.Net: Multicolumn Listview

Posted on 2012-04-06
4
536 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET bulk update  of a table from another table 4 44
Help with Syntax 9 36
VB.Net - Project Software to help the Developer 7 33
VB.Net - KeyPress Event 4 36
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

786 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