How to add new rows to Listview 
Author Message
 How to add new rows to Listview

Dear all,

          I know that I can add text ListView like that Set Item =
ListView1.ListItems.Add(, , "abc")
Then I want to add another new row to the ListView, how can I do that?
I have tried
Set Item = ListView1.ListItems.Add(2, , "abc") But the "2" is only for
column index but not row
index. Please suggest me how to Add a new row in Listview.

Thanks



Fri, 19 Aug 2011 12:27:18 GMT  
 How to add new rows to Listview

released on Sun, 1 Mar 2009 20:27:18 -0800 (PST) bearing the
following fruit:

Quote:
>Dear all,

>          I know that I can add text ListView like that Set Item =
>ListView1.ListItems.Add(, , "abc")
>Then I want to add another new row to the ListView, how can I do that?
>I have tried
>Set Item = ListView1.ListItems.Add(2, , "abc") But the "2" is only for
>column index but not row
>index. Please suggest me how to Add a new row in Listview.

the "2" is the row index not the column index. You code
should work as is so I'm not sure what the problem is here.

--
Jan Hyde

https://mvp.support.microsoft.com/profile/Jan.Hyde



Fri, 19 Aug 2011 21:11:44 GMT  
 How to add new rows to Listview
thanks Jan,

               But you can try to use the abouve code. You will find
that it only add
a new column but not a new row.

Thanks



Sat, 20 Aug 2011 12:09:04 GMT  
 How to add new rows to Listview


Quote:
> Dear all,

>          I know that I can add text ListView like that Set Item =
> ListView1.ListItems.Add(, , "abc")
> Then I want to add another new row to the ListView, how can I do that?
> I have tried
> Set Item = ListView1.ListItems.Add(2, , "abc") But the "2" is only for
> column index but not row
> index. Please suggest me how to Add a new row in Listview.

The Index is the row index and specifes where to position the row being
added.  Usually you just omit that and it adds the new row at the end.
Running the code you posted results in two list items being added; if you
are seeing it as two "columns" then my guess is that you didn't set the View
property right and you're getting the Icon view which does look like 2
columns when you don't specify icons.

Dim oItem As MSComctlLib.ListItem
Dim oHdr As MSComctlLib.ColumnHeader
Dim x As Long
ListView1.View = lvwReport
ListView1.FullRowSelect = True
Set oHdr = ListView1.ColumnHeaders.Add(, , "Item Name")
Set oHdr = ListView1.ColumnHeaders.Add(, , "Sub Item")
Set oHdr = ListView1.ColumnHeaders.Add(, , "Second Sub")
For x = 1 To 10
  Set oItem = ListView1.ListItems.Add(, , "Item " & CStr(x))
  oItem.SubItems(1) = "Sub 1-" & CStr(x)
  oItem.SubItems(2) = "Sub 2-" & CStr(x)
Next
Set oItem = ListView1.ListItems.Add(4, , "This one goes in the middle")

If you don't have sub items for each row then you can also try using the
List view:

Dim oItem As MSComctlLib.ListItem
Dim x As Long
ListView1.View = lvwList
Set oItem = ListView1.ListItems.Add(, , "Item 1")
Set oItem = ListView1.ListItems.Add(, , "Item 2")



Sat, 20 Aug 2011 12:27:00 GMT  
 How to add new rows to Listview

released on Mon, 2 Mar 2009 20:09:04 -0800 (PST) bearing the
following fruit:

Quote:
>thanks Jan,

>               But you can try to use the abouve code. You will find
>that it only add
>a new column but not a new row.

I did try your code. I suspect you don't have it in report
mode.

J

Quote:
>Thanks

--
Jan Hyde

https://mvp.support.microsoft.com/profile/Jan.Hyde



Sat, 20 Aug 2011 20:47:01 GMT  
 How to add new rows to Listview
Thanks to You all. I know how to use listview now.


Tue, 23 Aug 2011 14:13:34 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Add/Delete a row in a ListView

2. datagrid - catching whether editing or adding a new row

3. how to prevent adding new rows to a datagrid

4. Adding new rows to related tables on a dataset

5. Adding a new row to a Dataset

6. HELP with adding new rows to a dataset

7. how to add a new a row in unbound dbgrid

8. how to add a new row in the unbound dbgrid

9. vb4 sstab control problem adding new row of tabs

10. Add a new ROW in a CSV file

11. Add new row to a table dynamically

12. FLEXGRID - Clearing and Adding New Row?

 

 
Powered by phpBB® Forum Software