Click here to Skip to main content
15,868,419 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created 2 collumns in a listview vb net 2012, how can I add text in columns?
this works :
VB
ListView1.Items(0).SubItems(0).Text = x.ToString

but how can I add multiple values in a for...next loop
this doesn't work
VB
 For c = 0 To 10.....
ListView1.Items(c).SubItems(0).Text = x.ToString
Posted
Updated 2-Jul-15 21:20pm
v3
Comments
Michael_Davies 3-Jul-15 2:48am    
Question is confusing, you say "add items text", you say ListView but the code shows DataGridView, from that I presume therefore that you have already loaded the DGV with items and are then wanting to populate the ListView with the first column of the DGV.

If you are loading a ListView from a DataGridView then you need to ADD to the ListView:

For Each Line As DataGridViewRow In DataGridView1.Rows
ListView1.Items.Add(New ListViewItem(Line.Cells.Item(0).Value))
next

If you are UPDATING the ListView which already contains the text from the DGV rows you have to locate the correct ListViewItem as there may not be a one to one correspondence between the controls i.e. no guarantee that row 1 of the DGV is the row 1 of the LV, the LV might have been sorted differently.

Once located just : ListView1.Items(c).Text = x.tostring

1 solution

VB
For i = 0 To 10
           ListView1.items.add(("fdghhdhd").subitems.Add("fdghhdhd")

found it thank you michael for the comment
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900