Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB.Net: Multicolumn Listview

Posted on 2012-04-06
4
Medium Priority
?
575 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 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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 …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

926 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