469,621 Members | 1,748 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,621 developers. It's quick & easy.

Adding a listview item

Whilst looping through items in a listview I wish to have the option of
inserting a new row (in the middle not necessarily at the end of the
listview).

thus if lvw is the listview name

dim itm as listviewitem

For each itm in lvw.Items
'if certain condition is met then insert new row in the listview here
'row must be inserted immediately under the current item
next itm

Thanks
Gerry
Nov 21 '05 #1
2 2301
This does the trick:

Dim itm As listviewitem
Dim MaxItems As Integer = lvw.Items.Count - 1 '0-based
Dim Counter As Integer
Do While Counter <= MaxItems
itm = lvw.Items(Counter)
If CInt(itm.Text.Substring(4, 2)) / 2 = CInt(CInt(itm.Text.Substring(4,
2)) / 2) Then 'don't mind my "certain condition
'if certain condition is met then insert new row in the listview
here
'row must be inserted immediately under the current item
lvw.Items.Insert(itm.Index, New ListViewItem("New item"))
Counter += 1
MaxItems += 1
End If
Counter += 1
Loop

Hope this helps,
Stefan

"dotnetnewbie" <do**********@discussions.microsoft.com> wrote in message
news:05**********************************@microsof t.com...
Whilst looping through items in a listview I wish to have the option of
inserting a new row (in the middle not necessarily at the end of the
listview).

thus if lvw is the listview name

dim itm as listviewitem

For each itm in lvw.Items
'if certain condition is met then insert new row in the listview here
'row must be inserted immediately under the current item
next itm

Thanks
Gerry

Nov 21 '05 #2
thanks

the line

lvw.Items.Insert(itm.Index, New ListViewItem("New item"))

was just what I was after.

Gerry

"Stefan De Schepper" wrote:
This does the trick:

Dim itm As listviewitem
Dim MaxItems As Integer = lvw.Items.Count - 1 '0-based
Dim Counter As Integer
Do While Counter <= MaxItems
itm = lvw.Items(Counter)
If CInt(itm.Text.Substring(4, 2)) / 2 = CInt(CInt(itm.Text.Substring(4,
2)) / 2) Then 'don't mind my "certain condition
'if certain condition is met then insert new row in the listview
here
'row must be inserted immediately under the current item
lvw.Items.Insert(itm.Index, New ListViewItem("New item"))
Counter += 1
MaxItems += 1
End If
Counter += 1
Loop

Hope this helps,
Stefan

"dotnetnewbie" <do**********@discussions.microsoft.com> wrote in message
news:05**********************************@microsof t.com...
Whilst looping through items in a listview I wish to have the option of
inserting a new row (in the middle not necessarily at the end of the
listview).

thus if lvw is the listview name

dim itm as listviewitem

For each itm in lvw.Items
'if certain condition is met then insert new row in the listview here
'row must be inserted immediately under the current item
next itm

Thanks
Gerry


Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by J_Max | last post: by
2 posts views Thread by Anushya devi | last post: by
reply views Thread by Andrew | last post: by
2 posts views Thread by John R. | last post: by
9 posts views Thread by Kadett | last post: by
6 posts views Thread by Brandon McCombs | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.