Click here to Skip to main content
15,888,139 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
hi
I'm having fixed rows in listview with values.. Now i want add some more rows in the same listview.

ListView

Expense Amount
AAA 120
BBB 120
CCC 120

Afte that i used this following lines to addd the items in LV
VB
Dim lv4 As ListViewItem = lvexp.Items.Add(cb_exp.Text)
       lv4.SubItems.Add(txt_amt.Text)


I can't add the the items.. Hep Me......
Posted
Updated 30-May-12 23:03pm
v2
Comments
Ed Nutting 31-May-12 4:10am    
This is very unclear. What is the problem here? You have said "I can add the items" - did you mean "can't"? What is going wrong? Do they just not display or does an error occur? Please update your question using the Improve Question link above.

Thanks,
Ed

An example on ListView is given here http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.listviewitemcollection.aspx#Y3100[^]

In the above example there are two columns, similar to the number of columns specified in the question.

The following code
VB
Dim lv4 As ListViewItem = lvexp.Items.Add(cb_exp.Text)
lv4.SubItems.Add(txt_amt.Text)

added another row in the ListView without any error.

Please see the above example. I think it may be helpful.
 
Share this answer
 
v2
Comments
Espen Harlinn 1-Jun-12 4:16am    
5'ed!
VJ Reddy 1-Jun-12 5:50am    
Thank you, Espen :)
hi PunithaSabareeswari395,

You need to declare a new object, in this case, a ListViewItem that will hold all the data that has to be added in the Listview and then add it in your listview using AddRange and not Add. This is because, if you use Add only, you pass only one item but if you use AddRange, you can pass as many items as you want

Below is a sample code to solve your problem.



C#
Dim mylists As New ListViewItem(New String() {cb_exp.Text}, -1)
        ListView1.Items.AddRange(New System.Windows.Forms.ListViewItem() {mylists})
        ListView1.Focus()


Just try this. Hope it helps you! :)
 
Share this answer
 
Comments
PunithaSabareeswari 31-May-12 5:04am    
Thank you...
Prasad_Kulkarni 1-Jun-12 7:19am    
If it's really helpful for you then formally 'Accept solution'

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